//二分 + 最短路
//二分枚举最小的花费c, 将 >c 的路径的权值设为1,将 ≤c 的路径的权值设为0
//然后寻找从 1~n 的最短路径,dis[n] 就是 设最小花费为c的前提下 最少的 免费升级的电缆的数量
//二分枚举 直到找到满足条件的最小花费c
//注意到 k 有可能是 0 并且有可能找不到这样一条路径 所以二分枚举的范围设置成 [0, 1e6+1]
//最小花费是 0 很容易理解
//枚举区间加上 1e6+1 是因为:
// 1. 有可能最后的最小花费是 1e6
// 2. 当找不到这样一条路径的时候 二分的结果 r == 1e6+1 就很容易知道是没有这样一条路径
// 如果二分的范围只设置到 [0, 1e6] 那么二分的结果 r == 1e6 ,结果和最小花费 c == 1e6
// 的结果是一样的,还需要用其他的方法加以判断,而范围设置为 [0, 1e6+1] 就很巧妙的解决了这个问题
//另外,这里求最短路的时候,因为只有 0、1 两种权值,可以用双端队列广搜的方法求 dis[n]
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10, P = 1e4+10;
int n, p, k;
int h[N], e[2*P], ne[2*P], w[2*P], idx;
int dis[N];
bool vis[N];
void add(int a, int b, int c){
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
bool check(int a){
memset(dis, 0x3f, sizeof dis);
memset(vis, false, sizeof vis);
dis[1] = 0;
deque<int> q;
q.push_front(1);
while(q.size()){
int t = q.front();
q.pop_front();
if(vis[t]) continue;
vis[t] = true;
//if(t==n) return dis[n]<=k; //提前退出
for(int i=h[t]; ~i; i=ne[i]){
int j = e[i], ww = (int)(w[i]>a);
if(dis[j] > dis[t]+ww){
dis[j] = dis[t]+ww;
if(ww) q.push_back(j);
else q.push_front(j);
}
}
}
return dis[n]<=k;
}
int main(){
scanf("%d%d%d", &n, &p, &k);
memset(h, -1, sizeof h);
int a, b, c;
for(int i=0; i<p; i++){
scanf("%d%d%d", &a, &b, &c);
add(a, b, c), add(b, a, c);
}
int l = 0, r = 1e6+1, mid;
while(l<r){
mid = (l+r)>>1;
if(check(mid)) r = mid;
else l = mid+1;
}
if(r==1e6+1) puts("-1");
else cout<< r<< endl;
return 0;
}