mod=998244353 #N,Q=map(int, input().split()) import heapq from heapq import heappop,heappush,heapify from sys import stdin, setrecursionlimit input = stdin.readline readline = stdin.readline H,W=map(int, input().split()) sy,sx=map(int, input().split()) gy,gx=map(int, input().split()) sy-=1;sx-=1;gy-=1;gx-=1 from collections import deque d=deque() C=[0]*(H*W) s=sy*W+sx C[s]=1 d.append((C,sy,sx)) dx,dy=[1,-1,0,0],[0,0,1,-1] ans=0 for t in range(230): nd=deque() while d: C,y,x=d.popleft() for i in range(4): ny,nx=y+dy[i],x+dx[i] if 0<=ny