import heapq h,w=map(int,input().split()) u,d,r,l,k,p=map(int,input().split()) sy,sx,gy,gx=map(int,input().split()) sy-=1;sx-=1;gy-=1;gx-=1 g=[input() for _ in range(h)] inf=float('inf') dst=[[inf]*w for _ in range(h)] confirmed=[[False]*w for _ in range(h)] q=[] heapq.heappush(q,(0,sy,sx)) while q: cost,y,x=heapq.heappop(q) if confirmed[y][x]: continue confirmed[y][x]=True dst[y][x]=cost dy=[-1,1,0,0] dx=[0,0,1,-1] move_cost=[u,d,r,l] for i in range(4): ny=y+dy[i] nx=x+dx[i] if not(0<=ny