import heapq n, m, x = map(int, input().split()) e = [[] for _ in range(n)] for _ in range(m): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 e[u].append([v, a, b]) e[v].append([u, a, b]) l, r = -1, 1 << 30 while r - l > 1: piv = (l + r) // 2 dist = [1 << 60] * n dist[0] = 0 h = [0] while h: tmp = heapq.heappop(h) d, u = divmod(tmp, n) if d > x: break if u == n: break if dist[u] < d: continue for v, a, b in e[u]: if b < piv: continue if d + a < dist[v]: dist[v] = d + a heapq.heappush(h, dist[v]*n+v) if dist[-1] <= x: l = piv else: r = piv print(l)