#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, x2, y1, y2, a;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (x1 == x2 && y1 != y2)
    a = abs(y1 - y2) + min(2 * x1, 2 * (n - x1));
  else if (y1 == y2 && x1 != x2)
    a = abs(x1 - x2) + min(2 * y1, 2 * (n - y1));
  else if (x1 == x2 && y1 == y2)
    a = 0;
  else
    a = min(x1 + x2, n - x1 + n - x2) + min(y1 + y2, n - y1 + n - y2);
  cout << a << endl;
  return 0;
}
