r, c = map(int, input().split()) sy, sx = map(int, input().split()) gy, gx = map(int, input().split()) c = [list(input()) for i in range(r)] print(abs(gy-sy)+abs(gx-sx))