#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6 + 10; const int M = 1e3 + 10; const int INF = 0x3f3f3f3f; int n, m, k; int h[N], e[N], ne[N], w[N], idx; int d[M]; bool st[M]; void add(int a, int b, int c) { e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx ++; } bool check(int x) { deque<int> q; memset(d, 0x3f, sizeof d); memset(st, false, sizeof st); q.push_back(1); d[1] = 0; while (q.size()) { auto t = q.front(); q.pop_front(); if (st[t]) continue; st[t] = true; for (int i = h[t]; i != -1; i = ne[i]) { int j = e[i]; int dist = w[i] > x; if (d[j] > d[t] + dist) { d[j] = d[t] + dist; if (!dist) q.push_front(j); else q.push_back(j); } } } return d[n] <= k; } void solve() { cin >> n >> m >> k; memset(h, -1, sizeof h); for (int i = 0; i < m; i ++) { int a, b, c; cin >> a >> b >> c; add(a, b, c); add(b, a, c); } int l = 0, r = 1e9; while (l < r) { int mid = l + r >> 1; if (check(mid)) r = mid; else l = mid + 1; } if (l > 1e6) cout << "-1" << endl; else cout << l << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }