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