
// i wants to take ioi
//binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define nn "\n"
#define pi pair<int, int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pb push_back
#define TASK ""
#define ms(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define All(a, n) a + 1, a + 1 + n
#define LOG 19

const int INF = 1e18;
const int mod = 1e9;
const int N = 105;
const int MOD = 998244353;

int bit[200000];
int n, sx, sy, vx, vy;
int d[N][N];
int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1};

bool check(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= n;
}
void nhap() {
    cin >> n;
    cin >> sx >> sy;
    cin >> vx >> vy;
}
void solve() {
    ms(d, -1);
    queue<pi> q;
    q.push({sx, sy});
    d[sx][sy] = 0;
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        if (x == vx && y == vy) {
            cout << d[x][y] << nn;
            return;
        }
        for (int k = 0; k < 8; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (check(nx, ny) && d[nx][ny] == -1) {
                d[nx][ny] = d[x][y] + 1;
                q.push({nx, ny});
            }
        }
    }
    cout << 0 << nn;
}
signed main() {
    if (fopen(TASK ".INP", "r")) {
        freopen(TASK ".INP", "r", stdin);
        freopen(TASK ".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    nhap();
    solve();
    return 0;
}
