#include <bits/stdc++.h>
using namespace std;
int n;
int abs(int a) { return a < 0 ? -a : a; }
int whichside(int x, int y) {
  if (y == 0) return 0;
  if (x == n) return 1;
  if (y == n) return 2;
  if (x == 0) return 3;
}
int thisside(int x, int y) {
  int u = whichside(x, y);
  if (u == 0) return x;
  if (u == 1) return y;
  if (u == 2) return n - x;
  if (u == 3) return n - y;
}
int main() {
  int x1, y1, x2, y2;
  while (5 == scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2)) {
    int d1 = whichside(x1, y1) * n + thisside(x1, y1);
    int d2 = whichside(x2, y2) * n + thisside(x2, y2);
    printf("%d\n", min(abs(d1 - d2), 4 * n - abs(d1 - d2)));
  }
}
