#include using namespace std; using ll = long long; template using pq = priority_queue, greater>; vector dijkstra(vector>> &E, ll start, ll c){ ll N = E.size(); ll from, alt, d; pq> que; vector dist(N, 9e18); vector visit(N); dist[start] = 0; que.push({0, start}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (visit[from]) continue; visit[from] = 1; for (auto [to, C, D] : E[from]){ if (D < c) continue; alt = d + C; if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } return dist; } int main(){ ll N, M, X, A, B, u, v; cin >> N >> M >> X; vector>> E(N); for (int i=0; i> u >> v >> A >> B; u--; v--; E[u].push_back({v, A, B}); E[v].push_back({u, A, B}); } ll l=0, r=1e9+1, c; while(r-l>1){ c = (r+l)/2; vector dist = dijkstra(E, 0, c); if (dist[N-1] <= X) l = c; else r = c; } vector dist = dijkstra(E, 0, l); if (dist[N-1] > X){ cout << -1 << endl; return 0; } cout << l << endl; return 0; }