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 = [] adj = [[] for _ in range(N+1)] C01 = {} for _ in range(M): a, b, c = map(int, input().split()) ABC.append((a, b, c)) adj[a].append(b) adj[b].append(a) C01[a * (N + 1) + b] = 0 ok = L ng = -1 mid = (ok + ng) // 2 while ok - ng > 1: for a, b, c in ABC: if c > mid: C01[a * (N + 1) + b] = 1 else: C01[a * (N + 1) + b] = 0 que = deque() que.append(L+1) seen = [-1] * (N+1) while que: vd = que.popleft() v, d = divmod(vd, L+1) if seen[v] != -1: continue seen[v] = d for u in adj[v]: uu, vv = min(u, v), max(u, v) c = C01[uu * (N+1) + vv] if seen[u] == -1: if c: que.append(u * (L+1) + d + 1) else: que.appendleft(u * (L+1) + d) if seen[N] < K: ok = mid else: ng = mid mid = (ok + ng) // 2 print(ok) if __name__ == '__main__': main()