# import pypyjit;pypyjit.set_param("max_unroll_recursion=-1") # from bisect import * from collections import * from heapq import * # from itertools import * # from math import * # from datetime import * # from decimal import * # PyPyだと遅い # from string import ascii_lowercase,ascii_uppercase # import numpy as np import sys # sys.setrecursionlimit(10**6) # PyPyだと遅い INF = 10**20 MOD = 998244353 # MOD = 10**9 + 7 File = sys.stdin def input(): return File.readline()[:-1] # /////////////////////////////////////////////////////////////////////////// def Dijkstra(G, num_nodes, start_node, arg): heap = [(0, start_node, INF)] dist = [INF] * num_nodes dist[start_node] = 0 flag = [False] * num_nodes cnt = 0 for _ in range(INF): if len(heap) == 0: break popV = heappop(heap) if flag[popV[1]]: continue for i in G[popV[1]]: if i[2] < arg: continue dist[i[1]] = min(dist[i[1]], popV[0] + i[0]) heappush(heap, (dist[i[1]], i[1])) flag[popV[1]] = True cnt += 1 if cnt == num_nodes: break return dist[-1] # 最大 def is_ok(arg): return Dijkstra(G, N, 0, arg) < X def meguru_bisect(ng, ok): """ 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義すべし ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す """ for _ in range(10**18): if not abs(ng - ok) > 1: break mid = (ng + ok) // 2 if is_ok(mid): ng = mid else: ok = mid return ng N, M, X = map(int, input().split()) roads = [list(map(int, input().split())) for _ in range(M)] G = defaultdict(set) for u, v, a, b in roads: G[u - 1].add((a, v - 1, b)) G[v - 1].add((a, u - 1, b)) print(meguru_bisect(-1, INF))