from collections import deque H, W = map(int,input().split()) a, b = map(int,input().split()) s,t,x,y = map(int,input().split()) c, d = map(int,input().split()) s, t, x, y,c,d,a,b = s-1, t-1, x-1, y-1, c-1, d-1,a-1,b-1 li = [[10 ** 9] * W for _ in range(H)] li[a][b] = 0 q = deque() q.append((a, b)) h = [-1,0,1,0] w = [0,1,0,-1] while(q): p = q.popleft() for k in range(4): pos_x = p[0] + h[k] pos_y = p[1] + w[k] if(0 <= pos_x < H and 0 <= pos_y < W): if(li[pos_x][pos_y] == 10 ** 9): q.append((pos_x, pos_y)) li[pos_x][pos_y] = li[p[0]][p[1]] + 1 num = 10 ** 9 for i in range(s, x+1): for j in range(t, y+1): if(num > li[i][j]): num = li[i][j] pos = [i, j] print(num + abs(c - pos[0]) + abs(d- pos[1]) + abs(c - a) + abs(d - b))