// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll,ll>;
#define pb push_back
#define int long long
#define double long double
#define INF (ll) 3e18
// Ctrl + Shift + B コンパイル
// Ctrl + C 中断
// ./m 実行


signed main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<tuple<int,int,int>>> E(n);
  rep(i,m){
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    E[u].emplace_back(v, a, b);
    E[v].emplace_back(u, a, b);
  }
  int ok = -1;
  int ng = INF;
  while(ng - ok != 1){
    int mid = (ng + ok) / 2;
    vl dist(n, INF);
    dist[0] = 0;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, 0);
    while(pq.size()){
      auto [cost, now] = pq.top(); pq.pop();
      if (dist[now] != cost) continue;
      for(auto [to, a, b] : E[now]){
        if (b >= mid){
          if (dist[to] <= dist[now] + a) continue;
          dist[to] = dist[now] + a;
          pq.emplace(dist[to], to);
        }
      }
    }
    // cout << dist[n] << " " << mid << endl;
    if (dist[n-1] <= x) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}