import heapq INF=10**18 N,M=map(int,input().split()) G=[[]for i in range(N)] for i in range(M): A,B,C=map(int,input().split()) G[A-1]+=[(B-1,C)] G[B-1]+=[(A-1,C)] T=list(map(int,input().split())) dist=[[INF]*1002 for i in range(N)] dist[0][0]=0 PQ=[(0,0,0)] while PQ: c,v,p=heapq.heappop(PQ) if dist[v][p]c+e[1]//p: dist[e[0]][p]=c+e[1]//p heapq.heappush(PQ,(c+e[1]//p,e[0],p)) print(min(dist[N-1]))