mod = 1000000007 eps = 10**-9 L = 2*10**5 def main(): import sys from collections import deque input = sys.stdin.buffer.readline N, M, K = map(int, input().split()) ABC = [] for _ in range(M): ABC.append(tuple(map(int, input().split()))) ok = 1 ng = -1 mid = (ok + ng) // 2 while ok - ng > 1: adj = [[] for _ in range(N+1)] for a, b, c in ABC: if c > mid: adj[a].append((b, 1)) adj[b].append((a, 1)) else: adj[a].append((b, 0)) adj[b].append((a, 0)) que = deque() que.append((1, 0)) seen = [-1] * (N+1) while que: v, d = que.popleft() if seen[v] != -1: continue seen[v] = d for u, c in adj[v]: if seen[u] == -1: if c: que.append((u, d+1)) else: que.appendleft((u, d)) if seen[N] < K: ok = mid else: ng = mid mid = (ok + ng) // 2 print(ok) if __name__ == '__main__': main()