#include <bits/stdc++.h>
const int maxn = 5000000;
using namespace std;
int ab(int a) {
  if (a < 0) a *= -1;
  return a;
}
int main() {
  int n, x1, y1, x2, y2, ans;
  while (scanf("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2) != EOF) {
    if (ab(x1 - x2) != n && ab(y1 - y2) != n) {
      ans = ab(x1 - x2) + ab(y1 - y2);
      printf("%d\n", ans);
      continue;
    }
    n *= 4;
    x1 = x1 + x2 + y1 + y2;
    n -= x1;
    n = n > x1 ? x1 : n;
    printf("%d\n", n);
  }
  return 0;
}
