#include <bits/stdc++.h>
using namespace std;
int n;
inline int f(pair<int, int> a) {
  int ret = 0;
  if (a.first == 0) return a.second;
  ret += n;
  if (a.second == n) return ret + a.first;
  ret += n;
  if (a.first == n) return ret + n - a.second;
  ret += n;
  if (a.second == 0) return ret + n - a.first;
  ret += n;
  return ret;
}
int main() {
  pair<int, int> a, b;
  scanf("%d", &n);
  scanf("%d %d %d %d", &a.first, &a.second, &b.first, &b.second);
  int p = abs(f(a) - f(b));
  printf("%d\n", min(p, n * 4 - p));
  return 0;
}
