#include <bits/stdc++.h>
using namespace std;
int ab(int k) {
  if (k < 0)
    return k * (-1);
  else
    return k;
}
int main() {
  int i, j, k, l, m, n, a, b, c, d, r, s, ans;
  cin >> n >> a >> b >> c >> d;
  r = ab(a - c);
  s = ab(b - d);
  if (r == n || n == s)
    a = a + b + c + d;
  else
    a = r + s;
  ans = min(4 * n - a, a);
  cout << ans;
}
