#include <bits/stdc++.h>
using namespace std;

void solve(int n) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    auto safe = [&](int x, int y) {
        return a <= x && x <= c && b <= y && y <= d;
    };
    auto dist = [&](int x, int y) {
        if (a <= x && x <= c) {
            return min(abs(y - b), abs(y - d));
        }
        if (b <= y && y <= d) {
            return min(abs(a - x), abs(c - x));
        }
        return min(abs(x - a), abs(x - c)) + min(abs(y - b), abs(y - d));
    };
    auto kyori = [&](int xp, int yp, int x, int y) {
        if (safe(xp, yp) && safe(x, y)) return 0;
        if (safe(xp, yp)) return dist(x, y);
        if (safe(x, y)) return dist(xp, yp) - 1;
        return min(dist(x, y) + dist(xp, yp) - 1, abs(x - xp) + abs(y - yp));
    };
    int ans = 0;
    int xp, yp;
    cin >> xp >> yp;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        ans += kyori(xp, yp, x, y);
//        cerr << "Step: " << i << ": " << kyori(xp, yp, x, y) << endl;
        xp = x;
        yp = y;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;
        solve(n);
    }
}
