#include #define rep(i,n) for (int i=0; i < (int)(n); i++) #define all(c) c.begin(), c.end() using namespace std; typedef long long ll; typedef long double ld; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; int main() { ios::sync_with_stdio(0); cin.tie(0); //入出力高速化 //でかい虫の全マスチェック int H,W; cin>>H>>W; int A,B; cin>>A>>B; int h1,w1,h2,w2; cin>>h1>>w1>>h2>>w2; int P,Q; cin>>P>>Q; auto len = [](int a,int b,int c,int d) ->int { return abs(a-c) + abs(b-d); }; int ans = 1e9; for(int h=h1; h<=h2; h++) for(int w=w1; w<=w2; w++) { ans = min(ans, len(A,B,h,w) + len(h,w,P,Q)); } ans += len(P,Q,A,B); cout<