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