/* -*- coding: utf-8 -*-
 *
 * 2739.cc:  No.2739 Time is money - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef vector<pil> vpil;

/* global variables */

vpil nbrs[MAX_N];
ll ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);

  for (int i = 0; i < m; i++) {
    int u, v, c, t;
    scanf("%d%d%d%d", &u, &v, &c, &t);
    u--, v--;
    ll w = (ll)t * x + c;
    nbrs[u].push_back({v, w});
    nbrs[v].push_back({u, w});
  }

  fill(ds, ds + n, LINF);
  ds[0] = 0;

  priority_queue<pli> q;
  q.push({0, 0});

  while (! q.empty()) {
    auto [ud, u] = q.top(); q.pop();
    ud = -ud;
    if (ds[u] != ud) continue;
    if (u == n - 1) break;

    for (auto [v, w]: nbrs[u]) {
      ll vd = ud + w;
      if (ds[v] > vd) {
	ds[v] = vd;
	q.push({-vd, v});
      }
    }
  }

  if (ds[n - 1] >= LINF)
    puts("-1");
  else {
    ll gt = (ds[n - 1] + x - 1) / x;
    printf("%lld\n", gt);
  }

  return 0;
}