#include<bits/stdc++.h>

using namespace std;
using pl=pair<long long,long long>;
using Graph=vector<vector<pl>>;

vector<long long> dijkstra(long long v,long long n,Graph &g){
  vector<long long> d(n,8e18);
  priority_queue<pl,vector<pl>,greater<pl>> pq;
  d[v]=0;
  pq.push({0,v});
  while(!pq.empty()){
    pl od=pq.top();pq.pop();
    if(d[od.second]!=od.first){continue;}
    for(auto &nx : g[od.second]){
      if(d[nx.first]>od.first+nx.second){
        d[nx.first]=od.first+nx.second;
        pq.push({d[nx.first],nx.first});
      }
    }
  }
  return d;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n,m,x;
  cin >> n >> m >> x;
  Graph g(n);
  for(long long i=0;i<m;i++){
    long long u,v,c,t;
    cin >> u >> v >> c >> t;
    u--;v--;
    g[u].push_back({v,t*x+c});
    g[v].push_back({u,t*x+c});
  }
  vector<long long> d=dijkstra(0,n,g);
  // for(auto &nx : d){cout << nx << " ";}cout << "\n";
  if(d[n-1]>4e18){cout << "-1\n";}
  else{
    cout << (d[n-1]+x-1)/x << "\n";
  }
  return 0;
}