#include <bits/stdc++.h>
using namespace std;
int day[100001];
int main() {
  int n, i, j, k = 0, x1, x2, y1, y2, r, second;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  r = abs(x1 - x2);
  second = abs(y1 - y2);
  if (r == n || second == n) {
    k = x1 + x2 + y1 + y2;
    cout << min(k, 4 * n - k);
  } else {
    k = abs(x1 - x2) + abs(y1 - y2);
    cout << min(k, 4 * n - k);
  }
}
