#include <bits/stdc++.h>
using namespace std;
void dark_knight() {
  long long n, a, b, d, r, c, s;
  cin >> n >> a >> b >> c >> d;
  r = abs(a - c);
  s = abs(b - d);
  a = (r == n || n == s) ? a + b + c + d : r + s;
  cout << min(4 * n - a, a);
  return;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    dark_knight();
  }
  return 0;
}
