#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (x1 == x2 && (x1 == 0 || x1 == n)) {
    cout << abs(y1 - y2) << "\n";
    return 0;
  } else if (y1 == y2 && (y1 == 0 || y1 == n)) {
    cout << abs(x1 - x2) << "\n";
    return 0;
  }
  long long ans = x1 + y1 + x2 + y2;
  long long tmp = y1 + y2 + (n - x1) + (n - x2);
  ans = min(ans, tmp);
  tmp = x1 + x2 + (n - y1) + (n - y2);
  ans = min(ans, tmp);
  tmp = 4 * n - x1 - x2 - y1 - y2;
  ans = min(ans, tmp);
  cout << ans << "\n";
  return 0;
}
