#include using namespace std; typedef long long ll; struct node{ int u,v; ll a,b; }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m; ll X; cin >> n >> m >> X; std::vector a(m); for(int i = 0;i < m;i ++){ cin >> a[i].u >> a[i].v >> a[i].a >> a[i].b; } auto check = [&](int x)->bool{ std::vector>> e; e.resize(n + 1); for(int i = 0;i < m;i ++){ if(a[i].b >= x){ e[a[i].u].push_back({a[i].v,a[i].a}); e[a[i].v].push_back({a[i].u,a[i].a}); } } vector dis(n + 1,1e18 + 7); std::vector vis(n + 1); priority_queue> q; dis[1] = 0; q.push({dis[1],1}); while(!q.empty()){ int u = q.top().second; q.pop(); if(vis[u])continue; vis[u] = 1; for(auto [v,w]:e[u]){ if(dis[v] > dis[u] + w){ dis[v] = dis[u] + w; q.push({-dis[v],v}); } } } if(dis[n] < X){ return true; }return false; }; int l = 0,r = 1e9,ans = -1; while(l <= r){ int mid = l + r >> 1; if(check(mid)){ l = mid + 1; ans = mid; }else r = mid - 1; } cout << ans << "\n"; return 0; }