output_description: Print the minimum number of times the magician needs to use the magic. If he
  cannot reach (D_h,D_w), print `-1` instead.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W
      C_h C_w
      D_h D_w
      S_{11}\ldots S_{1W}
      \vdots
      S_{H1}\ldots S_{HW}
attempt: h = 0
  w = 0
  reached = []
  maze = []
  dh = 0
  dw = 0
  
  
  def main():
      global h
      global w
      global dh
      global dw
      h, w = map(int, input().split())  # 迷路
      ch, cw = map(int, input().split())  # 魔法使い位置
      dh, dw = map(int, input().split())  # ゴール
      for i in range(h):
          maze.append(list(input()))
      # for (i, row) in enumerate(maze, 1):
      #     print('{}: {}'.format(i, row))
      warp_count = 0
      while True:
          if walk_to(ch, cw):
              # 到達
              # print('Goal!')
              print(warp_count)
              break
          else:
              # 行ったことのある場所からワープ
              mch, mcw = most_close()
              # print('一番近かったのは {},{}'.format(mch, mcw))
              warped_hw = warp_from(mch, mcw)
              if warped_hw is not None:
                  warp_count += 1
                  ch, cw = warped_hw
              else:
                  # 到達不能
                  # print('到達不能')
                  print(-1)
                  break
  
  
  def warp_from(mch, mcw):
      start_h = max(mch - 2, 1)
      end_h = min(mch + 2, h)
      start_w = max(mcw - 2, 1)
      end_w = min(mcw + 2, w)
  
      min_distance = None
      min_hw = None
      for i in range(start_h, end_h + 1):
          for j in range(start_w, end_w + 1):
              # print(i, j)
              if get_block(i, j) == "." and yet(i, j):
                  # print('{},{}にはワープできるね'.format(i, j))
                  distance = abs(dh - i) + abs(dw - j)
                  if min_distance is None or distance < min_distance:
                      min_distance = distance
                      min_hw = [i, j]
      return min_hw
  
  
  def most_close():
      min_hw = []
      min_distance = None
      for r in reached:
          distance = max(abs(dh - r[0]), abs(dw - r[1]))
          if min_distance is None or distance < min_distance:
              min_distance = distance
              min_hw = [r[0], r[1]]
      return min_hw
  
  
  def walk_to(current_h, current_w):
      reached.append([current_h, current_w])  # 到達済み
      if current_h == dh and current_w == dw:
          return True
      # ↑
      if (
          current_h > 1
          and get_block(current_h - 1, current_w) == "."
          and yet(current_h - 1, current_w)
      ):
          # print('現在{},{}: 上に行けるよ'.format(current_h, current_w))
          return walk_to(current_h - 1, current_w)
      # →
      if (
          current_w < w
          and get_block(current_h, current_w + 1) == "."
          and yet(current_h, current_w + 1)
      ):
          # print('現在{},{}: 右に行けるよ'.format(current_h, current_w))
          return walk_to(current_h, current_w + 1)
      # ↓
      if (
          current_h < h
          and get_block(current_h + 1, current_w) == "."
          and yet(current_h + 1, current_w)
      ):
          # print('現在{},{}: 下に行けるよ'.format(current_h, current_w))
          return walk_to(current_h + 1, current_w)
      # ←
      if (
          current_w > 1
          and get_block(current_h, current_w - 1) == "."
          and yet(current_h, current_w - 1)
      ):
          # print('現在{},{}: 左に行けるよ'.format(current_h, current_w))
          return walk_to(current_h, current_w - 1)
  
      # print('現在{},{}: どこにも行けない'.format(current_h, current_w))
      return False
  
  
  def get_block(target_h, target_w):
      return maze[target_h - 1][target_w - 1]
  
  
  def yet(check_h, check_w):
      for r in reached:
          if check_h == r[0] and check_w == r[1]:
              return False
      return True
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  A maze is composed of a grid of H \times W squares - H vertical, W horizontal.
  
  The square at the i-th row from the top and the j-th column from the left -
  (i,j) \- is a wall if S_{ij} is `#` and a road if S_{ij} is `.`.
  
  There is a magician in (C_h,C_w). He can do the following two kinds of moves:
  
    * Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.
    * Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in.
  
  In either case, he cannot go out of the maze.
  
  At least how many times does he need to use the magic to reach (D_h, D_w)?
samples: [{"input": "4 4\n    1 1\n    4 4\n    ..#.\n    ..#.\n    .#..\n    .#..", "output": "1\n    \n\nFor example, by walking to (2,2) and then using the magic to travel to (4,4),\njust one use of magic is enough.\n\nNote that he cannot walk diagonally.\n\n* * *"}, {"input": "4 4\n    1 4\n    4 1\n    .##.\n    ####\n    ####\n    .##.", "output": "-1\n    \n\nHe cannot move from there.\n\n* * *"}, {"input": "4 4\n    2 2\n    3 3\n    ....\n    ....\n    ....\n    ....", "output": "0\n    \n\nNo use of magic is needed.\n\n* * *"}, {"input": "4 5\n    1 2\n    2 5\n    #.###\n    ####.\n    #..##\n    #..##", "output": "2"}]