n,m=map(int,input().split()) G=[[] for i in range(n)] E=[(int(a)-1,int(b)-1) for a,b in (input().split() for i in range(m))] for a,b in E: G[a].append(b) G[b].append(a) C=[int(_)-1 for _ in input().split()] W=[int(_) for _ in input().split()] def func(start,goal): import heapq from math import inf dist=[inf]*n dist[start]=W[C[start]] Q=[] heapq.heappush(Q,(dist[start],start,[i==C[start] for i in range(10)])) while Q: d,v,visited=heapq.heappop(Q) if v==goal: return dist[v] if d>dist[v]: continue for u in G[v]: d2=dist[v]+(0 if visited[C[u]] else W[C[u]]) if d2