#include <bits/stdc++.h>
using namespace std;
int n, x, y, xx, yy;
int f(int x, int y) {
  if (y == 0) return x;
  if (x == n) return n + y;
  if (y == n) return 2 * n + (n - x);
  if (x == 0) return 3 * n + (n - y);
}
int main() {
  cin >> n >> x >> y >> xx >> yy;
  int ans = abs(f(x, y) - f(xx, yy));
  cout << min(ans, 4 * n - ans) << endl;
  return 0;
}
