#include <bits/stdc++.h>
using namespace std;
struct reader {
  template <typename Type>
  reader& operator>>(Type& ret) {
    ret = 0;
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
      if (ch == '-') f = -f;
    for (; isdigit(ch); ch = getchar())
      ret = (ret << 1) + (ret << 3) + (ch - '0');
    ret *= f;
    return *this;
  }
} fin;
int n, a, b, c, d, r, s;
int main() {
  fin >> n >> a >> b >> c >> d;
  r = abs(a - c);
  s = abs(b - d);
  a = (r == n || n == s) ? a + b + c + d : r + s;
  printf("%d\n", min(4 * n - a, a));
  return 0;
}
