from heapq import heappop, heappush n, m, x = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): u, v, c, t = map(int, input().split()) c += t * x u -= 1 v -= 1 edges[u].append((v, c)) edges[v].append((u, c)) dist = [1 << 60] * n dist[0] = 0 hq = [0] while hq: tmp = heappop(hq) d = tmp // n pos = tmp - d * n if dist[pos] < d: continue for to, cost in edges[pos]: if dist[to] > d + cost: dist[to] = d + cost heappush(hq, to + n * dist[to]) ans = (dist[-1] + x - 1) // x if dist[-1] != 1 << 60 else -1 print(ans)