#include using namespace std; using ll = long long; using vll = vector; template using umap = unordered_map; #define rep(i, n) for (int i = 0; i < n;i++) #define rep1(i, n) for (int i = 1; i <= n;i++) #define rrep(i, n) for (int i = n - 1; i >= 0;i--) #define rrep1(i, n) for (int i = n; i >= 1;i--) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define INF 1LL << 60 #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; int a, b; cin >> a >> b; a--;b--; int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; r1--; c1--; r2--; c2--; int dx[4] = {0, 1, -1, 0}; int dy[4] = {1, 0, 0, -1}; queue> que; que.push({a, b, 0}); vector> visited(h, vector(w)); int bugX = 0, bugY = 0; int ans = 0; while (!que.empty()) { auto [x, y, d] = que.front(); que.pop(); if (visited[x][y]) { continue; } visited[x][y] = true; if (r1 <= x && x <= r2 && c1 <= y && y <= c2) { bugX = x; bugY = y; ans += d; break; } for (int i = 0;i < 4;i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || ny < 0 || nx >= h || ny >= w) { continue; } if (visited[nx][ny]) continue; que.push({nx, ny, d + 1}); } } int p, q; cin >> p >> q; p--;q--; ans += abs(p - bugX) + abs(q - bugY); ans += abs(p - a) + abs(q - b); cout << ans << endl; }