from collections import defaultdict,Counter,deque from heapq import heappush,heappop def main(): N,M,X =map(int,input().split()) e = [[] for _ in range(N)] m = 0 for _ in range(M): u,v,a,b = map(int,input().split()) u -= 1 v -= 1 m = max(b,m) e[u].append([v,a,b]) e[v].append([u,a,b]) for i in range(N): e[i].sort(key=lambda x:-x[2]) ok = -1 ng = m+1 while ng - ok > 1: mid = (ok + ng)//2 v = [1 << 60] * N v[0] = 0 f = [False] * N q = [] heappush(q,(0,0)) while q: t,p = heappop(q) if p == N-1: break if f[p]: continue f[p] = True for next,a,b in e[p]: if mid > b: break if mid <= b and t + a <= X and t + a < v[next]: v[next] = t + a heappush(q,(v[next],next)) if v[-1] <= X: ok = mid else: ng = mid print(ok) if __name__ == '__main__': main()