# include<bits/stdc++.h>
# define int long long
# define qwq for (int i = 1; i <= n; i++ ) { bj [i] = 0; }
using namespace std;
struct Node {
int to, w;
};
vector < Node > a [ 10001 ];
bool bj [ 10001 ];
int js [ 10001 ];
struct qaq {
int p, w, m;
}b[ 10001 ];
int tot = 0;
int n, p, k;
void work ( int x ) {
if ( x * 2 + 1 <= tot && b [ x * 2 + 1 ] . w < b [ x ] . w && b [ x * 2 + 1 ] . w < b [ x * 2 ] . w) {
swap ( b [ x ], b [ x * 2 + 1 ] );
work ( x * 2 + 1 );
}
else if ( x * 2 <= tot && b [ x * 2 ] . w < b [ x ] . w) {
swap ( b [ x * 2 ], b [ x ] );
work ( x * 2 );
}
}
void work1 ( int x ){
if ( b [ x / 2 ] . w > b [ x ] . w && x != 1 ){
swap ( b [ x / 2 ], b [ x ] );
work1 ( x / 2 );
}
}
void dij ( int p, int w, int m ){
bj [ p ] = 1;
js [ p ] = w;
for ( auto it : a [ p ] ) {
if ( ! bj [ it . to ] || w + ( it . w > m ) < js [ it . to ] ) {
b [ ++tot ] = { it . to, w + ( it . w > m ), m };
work1 ( tot );
bj [ it . to ] = 1;
}
}
}
bool check ( int w ){
b [ ++tot ] = { 1,0 };
while ( tot ){
dij ( b [ 1 ] . p, b [ 1 ] . w, w );
swap ( b [ 1 ], b [ tot ] );
tot--;
work ( 1 );
}
return js [ n ] <= k;
}
signed main ( ) {
scanf ( "%d %d %d", &n, &p, &k);
for (int i = 1; i <= p; i++ ) {
int u, v, w;
scanf( "%d %d %d", &u, &v, &w);
a [ u ] . push_back ({ v, w });
a [ v ] . push_back ({ u, w });
}
int l = 0, r = 1000000;
int ans = 0;
while ( l <= r ) {
int mid = l + r >> 1;
if ( check ( mid ) ) {
r = mid - 1;
ans = mid;
}
else {
l = mid + 1;
ans = mid + 1;
}
qwq;
tot = 0;
}
printf ( "%d", ans);
return 0;
}