# import bisect import copy import heapq import itertools import math import operator import random import sys from bisect import bisect, bisect_left, bisect_right, insort from collections import Counter, deque from fractions import Fraction from functools import cmp_to_key, lru_cache, partial from inspect import currentframe from math import ceil, gcd, log10, pi, sqrt from typing import Iterable, Iterator, List, Tuple, TypeVar, Union # import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') # import string # import networkx as nx input = sys.stdin.readline sys.setrecursionlimit(10000000) # mod = 10 ** 9 + 7 mod = 998244353 # mod = 1 << 128 # mod = 10 ** 30 + 1 INF = 1 << 61 DIFF = 10 ** -9 DX = [1, 0, -1, 0, 1, 1, -1, -1] DY = [0, 1, 0, -1, 1, -1, 1, -1] def read_values(): return tuple(map(int, input().split())) def read_index(): return tuple(map(lambda x: int(x) - 1, input().split())) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for _ in range(N)] def dprint(*values): print(*values, file=sys.stderr) def dprint2(*values): names = {id(v): k for k, v in currentframe().f_back.f_locals.items()} dprint(", ".join(f"{names.get(id(value), '???')}={repr(value)}" for value in values)) class UnionFind: def __init__(self, N): self.state = [-1] * N self.rank = [0] * N self.num_group = N def get_parent(self, a): p = self.state[a] if p < 0: return a q = self.get_parent(p) self.state[a] = q return q def make_pair(self, a, b): pa = self.get_parent(a) pb = self.get_parent(b) if pa == pb: return if self.rank[pa] > self.rank[pb]: pa, pb = pb, pa a, b = b, a elif self.rank[pa] == self.rank[pb]: self.rank[pb] += 1 self.state[pb] += self.state[pa] self.state[pa] = pb self.state[a] = pb self.num_group -= 1 def is_pair(self, a, b): return self.get_parent(a) == self.get_parent(b) def get_size(self, a): return -self.state[self.get_parent(a)] def validate(N, M, X, L): assert(1 <= N <= 2 * 10 ** 5) assert(1 <= M <= 2 * 10 ** 5) assert(1 <= X <= 10 ** 18) assert(len(L) == M) uf = UnionFind(N) for u, v, a, b in L: assert(1 <= u <= N) assert(1 <= v <= N) assert(1 <= a <= 10 ** 9) assert(1 <= b <= 10 ** 9) u -= 1 v -= 1 uf.make_pair(u, v) assert uf.get_size(0) == N assert uf.num_group == 1 def main(): N, M, X = read_values() L = read_lists(M) validate(N, M, X, L) G = [[] for _ in range(N)] for u, v, a, b in L: u -= 1 v -= 1 G[u].append((b, v, a)) G[v].append((b, u, a)) for i in range(N): G[i].sort(reverse=True) def f(m): S = [(0, 0)] fixed = [False] * N D = [INF] * N D[0] = 0 while S: c, i = heapq.heappop(S) if i == N - 1: break if fixed[i]: continue fixed[i] = True for b, j, a in G[i]: if m > b: break if D[j] <= c + a: continue D[j] = c + a heapq.heappush(S, (c + a, j)) return D[N - 1] <= X l = -1 r = 10 ** 9 + 10 while r - l > 1: m = (l + r) // 2 if f(m): l = m else: r = m print(l) if __name__ == "__main__": main()