def dist(pos1, pos2): r1, c1 = pos1 r2, c2 = pos2 return abs(r1 - r2) + abs(c1 - c2) H, W = [int(s) for s in input().split()] A, B = [int(s) for s in input().split()] R1, C1, R2, C2 = [int(s) for s in input().split()] P, Q = [int(s) for s in input().split()] start = (A, B) bugs = [(r, c) for r in range(R1, R2 + 1) for c in range(C1, C2 + 1)] trash = (P, Q) ans = min(dist(start, bug) + dist(bug, trash) + dist(trash, start) for bug in bugs) print(ans)