from collections import deque H,W=map(int,input().split()) sx,sy,gx,gy=map(int,input().split()) MAP=[list(map(int,list(input().strip()))) for i in range(H)] USE=[[0]*W for i in range(H)] USE[sx-1][sy-1]=1 Q=deque([(sx-1,sy-1)]) while Q: x,y=Q.popleft() for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z=0: if USE[x-2][y]==0 and MAP[x-2][y]==MAP[x][y] and MAP[x-1][y]=0: if USE[x][y-2]==0 and MAP[x][y-2]==MAP[x][y] and MAP[x][y-1]