import heapq N, M, X = map(int,input().split()) G = [[] for _ in range(N + 1)] for _ in range(M): u, v, a, b = map(int,input().split()) G[u].append((v, a, b)) G[v].append((u, a, b)) def d(m): H = [(0, 1)] F = [False] * (N + 1) D = [X + 1] * (N + 1) D[1] = 0 while H: t, i = heapq.heappop(H) if i == N: return t <= X if F[i]: continue F[i] = True for j, a, b in G[i]: t2 = t + a if m > b or t2 > X or D[j] <= t2: continue D[j] = t2 heapq.heappush(H, (t2, j)) return False l, r = -1, 10 ** 9 + 1 while r - l > 1: m = (l + r) // 2 l, r = (m, r) if d(m) else (l, m) print(l)