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