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()) def dist(X1, Y1, X2, Y2): return abs(X1 - X2) + abs(Y1 - Y2) ans = 10 ** 10 for r in range(R1, R2 + 1): for c in range(C1, C2 + 1): ans = min(ans, dist(A, B, r, c) + dist(r, c, P, Q) + dist(P, Q, A, B)) print(ans)