h,w=map(int,input().split()) u,d,r,l,k,p=map(int,input().split()) xs,ys,xt,yt=map(lambda x: int(x)-1,input().split()) s=[input() for _ in range(h)] dx=[0, 1, 0, -1] dy=[1, 0, -1, 0] cs=[r, d, l, u] import heapq pq=[] heapq.heapify(pq) n=h*w cost=[1e18]*n cost[xs*w+ys]=0 heapq.heappush(pq,[0,xs*w+ys]) while len(pq) > 0: c,v=heapq.heappop(pq) x,y=divmod(v, w) for i in range(4): nx=x+dx[i] ny=y+dy[i] if 0<=nx