#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, a, b;
  cin >> n >> x >> y >> a >> b;
  if (x == a && (x == 0 || x == n)) {
    cout << abs(y - b) << endl;
    return 0;
  }
  if (y == b && (y == 0 || y == n)) {
    cout << abs(x - a) << endl;
    return 0;
  }
  int co1 = x + y + a + b;
  int co2 = (n - x) + y + (n - a) + b;
  int co3 = x + (n - y) + a + (n - b);
  int co4 = (n - x) + (n - y) + (n - a) + (n - b);
  cout << min(min(co1, co2), min(co3, co4)) << endl;
}
