#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int n, m;
int a[maxn];
int main() {
  int x1, x2, y1, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (x1 == x2 && (x1 == 0 || x1 == n)) {
    cout << abs(y1 - y2) << endl;
  } else if (y1 == y2 && (y1 == 0 || y1 == n)) {
    cout << abs(x1 - x2) << endl;
  } else {
    if ((x1 == 0 && x2 == n) || (x1 == n && x2 == 0)) {
      cout << min((n - y1) + (n - y2) + n, y1 + y2 + n) << endl;
    } else if ((y1 == 0 && y2 == n) || (y1 == n && y2 == 0)) {
      cout << min((n - x1) + (n - x2) + n, x1 + x2 + n) << endl;
    } else {
      cout << max(x1, x2) - min(x1, x2) + max(y1, y2) - min(y1, y2) << endl;
    }
  }
  return 0;
}
