from collections import deque H, W = map(int, input().split()) A, B = map(int, input().split()) A -= 1 B -= 1 R1, C1, R2, C2 = map(int, input().split()) R1, C1, R2, C2 = R1 - 1, C1 - 1, R2 - 1, C2 - 1 P, Q = map(int, input().split()) P -= 1 Q -= 1 room = [[False]*W for _ in range(H)] for i in range(H): for j in range(W): if R1 <= i <= R2 and C1 <= j <= C2: room[i][j] = True q = deque() q.append([A, B]) while q: r, c = q.popleft() if room[r][c]: ar, ac = r, c break else: for di, dj in [(0, 1), (0, -1), (1, 0), (-1, 0)]: ni, nj = r + di, c + dj if not(0 <= ni < H and 0 <= nj < W): continue q.append([ni, nj]) def dist(x, y, dx, dy): return abs(x - dx) + abs(y - dy) print(dist(A, B, ar, ac) + dist(ar, ac, P, Q) + dist(P, Q, A, B))