#!/usr/bin/env python3 import collections import heapq IMPOSSIBLE = -1 Edge = collections.namedtuple("Edge", "start end money time") AdjVertex = collections.namedtuple("AdjVertex", "dest, money, time") State = collections.namedtuple("State", "time money vertex") def compute_min_time(num_vertices, money_limit, adj_vertices): pq = [] heapq.heappush(pq, State(0, 0, 0)) while pq: state0 = heapq.heappop(pq) if state0.vertex == num_vertices - 1: return state0.time for v in adj_vertices[state0.vertex]: new_money = state0.money + v.money if new_money <= money_limit: new_time = state0.time + v.time heapq.heappush(pq, State(new_time, new_money, v.dest)) else: return IMPOSSIBLE def main(): num_vertices = int(input()) money_limit = int(input()) _ = input() ss = map(lambda x: int(x) - 1, input().split()) ts = map(lambda x: int(x) - 1, input().split()) ys = map(int, input().split()) ms = map(int, input().split()) adj_vertices = [set() for _ in range(num_vertices)] for edge in (Edge(*args) for args in zip(ss, ts, ys, ms)): adj_vertices[edge.start].add(AdjVertex(*edge[1:])) answer = compute_min_time(num_vertices, money_limit, adj_vertices) print(answer) if __name__ == '__main__': main()