#include using namespace std; using ll = long long; using db = long double; using ch = char; using bl = bool; using st = string; using pll = pair; using psl = pair; using vst = vector; using vch = vector; using vvch = vector; using vbl = vector; using vvbl = vector; using vdb = vector; using vpll = vector; using vvpll = vector; using vpsl = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vvvvll = vector; using vvvvvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++) int main() { ll N,M,X; cin>>N>>M>>X; vector>> G(N); rep(i,M){ ll u,v,a,b; cin>>u>>v>>a>>b; u--,v--; G[u].push_back(make_pair(v,make_pair(a,b))); G[v].push_back(make_pair(u,make_pair(a,b))); } ll l=-1,r=1e10; vbl seen; vll dist; while(r-l>1){ ll m=(l+r)/2; seen.assign(N,0); dist.assign(N,2e18); priority_queue> q; q.push(make_pair(0,0)); dist[0]=0; while(!q.empty()){ ll v=q.top().second; q.pop(); for(auto p:G[v]){ ll u=p.first,a=p.second.first,b=p.second.second; if(seen[u])continue; if(dist[u]>dist[v]+a && m<=b){ dist[u]=dist[v]+a; q.push(make_pair(dist[u],u)); } } seen[v]=1; } if(dist[N-1]<=X)l=m; else r=m; } cout << l << endl; return 0; }