import heapq N,M,X = map(int,input().split()) G = [[] for _ in range(N)] 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)) inf = 1 << 67 def calc(k): dist = [inf] * N dist[0] = 0 q = [(0,0)] while q: d,now = heapq.heappop(q) if dist[now] > d:continue if now == N - 1:break for v,a,b in G[now]: if b < k:continue if dist[v] > d + a: dist[v] = d + a heapq.heappush(q,(d + a,v)) return dist[-1] <= X end = 10 ** 9 + 1 start = 0 while end - start > 1: mid = end + start >> 1 if calc(mid): start = mid else: end = mid print(start if start != 0 else -1)