H, W = map(int, input().split()) A, B = map(int, input().split()) R1, C1, R2, C2 = map(int, input().split()) P, Q = map(int, input().split()) res = 10 ** 9 for r in range(R1, R2 + 1): for c in range(C1, C2 + 1): time = 0 time = abs(A - r) + abs(B - c) + abs(P - r) + abs(Q - c) + abs(A - P) + abs(B - Q) res = min(res, time) print(res)