from heapq import heappush, heappop INF = 10 ** 20 def dijkstra(s, N): # (始点, ノード数) dist = [(0, INF) for _ in range(N)] hq = [(-INF, 0, s)] dist[s] = (INF, 0) seen = set() # ノードが確定済みかどうか while hq: w, d, v = heappop(hq) # ノードを pop する if v==N-1: return -w for to, cost, width in G[v]: # ノード v に隣接しているノードに対して nw = max(w, -width) nd = d+cost if nd<=X and (nw, nd, to) not in seen: tw, td = dist[to] if tw>=nw and td<=nd: continue dist[to] = (nw, nd) heappush(hq, (nw, nd, to)) seen.add((nw, nd, to)) return -1 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)) ans = dijkstra(0, N) print(ans)