from heapq import heapify,heappop,heappush N,M=map(int,input().split()) E=[[] for _ in range(N)] for _ in range(M): a,b,c=map(int,input().split()) a-=1; b-=1; E[a].append((b,c)) E[b].append((a,c)) T=list(map(int,input().split())) T_max=max(T) inf=float("inf") D=[[inf]*(T_max*(N-1)+1) for _ in range(N)] D[0][T[0]]=T[0] Q=[(T[0],0,T[0])] heapify(Q) while Q: d,x,t=heappop(Q) if x==N-1: break if D[x][t]