import collections height,width=map(int,input().split()) sx,sy=map(lambda x:int(x)-1,input().split()) gx,gy=map(lambda x:int(x)-1,input().split()) board=[] for _ in range(height): row=input() board.append([cell!='#' for cell in row]) queue=collections.deque([(sx,sy)]) visited=set() reachable=False while queue: x,y=queue.popleft() if (x,y) in visited: continue visited.add((x,y)) if (x,y)==(gx,gy): reachable=True break for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]: if 0<=x+dx