#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60; const int IINF = (1 << 30) - 1; template struct Edge{ int to; T w; T b; Edge(int to_, T w_, T b_){ to = to_; w=w_; b=b_; } }; template using Tree = vector>>; template using Graph = vector>>; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n, m, x; cin >> n >> m >> x; Graph G(n); rep(i, m){ ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; G[u].pb(Edge(v, a, b)); G[v].pb(Edge(u, a, b)); } //輸送可能チェック { vector dist(n, LINF); dist[0] = 0; priority_queue, greater> PQ; PQ.push({0, 0}); while(!PQ.empty()){ ll v = PQ.top().se; ll tmp = PQ.top().fi; PQ.pop(); if(dist[v] < tmp) continue; for(Edge e : G[v]){ if(dist[v]+e.w < dist[e.to]){ dist[e.to] = dist[v] + e.w; PQ.push({dist[e.to], e.to}); } } } if(dist[n-1]>x){ cout << -1 << endl; return 0; } } ll low = 0; ll high = 1e9+1; ll mid; while(high-low>1){ mid = (low + high)/2; vector dist(n, LINF); dist[0] = 0; priority_queue, greater> PQ; PQ.push({0, 0}); while(!PQ.empty()){ ll v = PQ.top().se; ll tmp = PQ.top().fi; PQ.pop(); if(dist[v] < tmp) continue; for(Edge e : G[v]){ if(dist[v]+e.w