D_x, D_y = map(int, input().split())
A_x, A_y = map(int, input().split())
B_x, B_y = map(int, input().split())

if B_y > A_y:
    up = A_y + D_y - B_y
else:
    up = A_y - B_y

if B_y < A_y:
    down = D_y - A_y + B_y
else:
    down = B_y - A_y

if B_x > A_x:
    left = A_x + D_x - B_x
else:
    left = A_x - B_x

if B_x < A_x:
    right = D_x - A_x + B_x
else:
    right = B_x - A_x

print(min(up, down) + min(left, right), end="")