from heapq import heappop, heappush n, m, T = map(int, input().split()) B = [-1] edges = [[] for _ in range(n)] for _ in range(m): u, v, a, b = map(int, input().split()) u -= 1 v -= 1 edges[u].append((v, a, b)) edges[v].append((u, a, b)) B.append(b) def ok(x): dist = [T + 1] * n dist[0] = 0 hq = [0] while hq: tmp = heappop(hq) d = tmp // n pos = tmp - d * n if dist[pos] < d: continue for npos, a, b in edges[pos]: if b < x: continue nd = d + a if nd < dist[npos]: dist[npos] = nd heappush(hq, nd * n + npos) return dist[n - 1] <= T B = sorted(set(B)) l = 0 r = len(B) while r - l > 1: mid = (l + r) // 2 if ok(B[mid]): l = mid else: r = mid print(B[l])