#!/usr/bin/env python3 # -*- coding: utf-8-auto -*- 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()) min_length = 9999999999999999999 cross_position = None for r in range(R1, R2+1): for c in range(C1, C2+1): if min_length > abs(A-r) + abs(B-c) + abs(P-r) + abs(Q-c): min_length = abs(A-r) + abs(B-c) + abs(P-r) + abs(Q-c) cross_position = (r, c) print(min_length + abs(P-A) + abs(Q-B))