from collections import defaultdict from heapq import heappop, heappush n, m, x = map(int, input().split()) G = defaultdict(list) for _ in range(m): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 G[u].append((v, a, b)) G[v].append((u, a, b)) left, right = -1, 10**9 + 10 while right - left > 1: mid = (left + right) // 2 DP = [x + 1 for _ in range(n)] DP[0] = 0 H = [(0, 0)] while H: cc, cp = heappop(H) if cc > DP[cp]: continue for np, a, b in G[cp]: if b < mid: continue if cc + a >= DP[np]: continue DP[np] = cc + a heappush(H, (cc + a, np)) if DP[n - 1] == x + 1: right = mid else: left = mid print(left)