import heapq n, m, x = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(m): a, b, c, t = list(map(int, input().split())) a -= 1 b -= 1 g[a].append((b, t*x + c)) g[b].append((a, t*x + c)) INF = 10**18 pq = [(0, 0)] dist = [INF] * n while pq: d, v = heapq.heappop(pq) if dist[v]!=INF: continue dist[v] = d for u, c in g[v]: if dist[u]==INF: heapq.heappush(pq, (d+c, u)) if dist[n-1]==INF: print(-1) else: print((dist[n-1]+x-1)//x)