#include <bits/stdc++.h>
int main(void) {
  int n, x[2], y[2], p[2], i;
  scanf("%d %d %d %d %d", &n, &x[0], &y[0], &x[1], &y[1]);
  for (i = 0; i < 2; i++) {
    if (y[i] == 0) {
      p[i] = x[i];
      continue;
    }
    if (x[i] == n) {
      p[i] = n + y[i];
      continue;
    }
    if (y[i] == n) {
      p[i] = n + n + n - x[i];
      continue;
    }
    p[i] = n + n + n + n - y[i];
  }
  n *= 4;
  printf("%d\n", ((((p[0] - p[1] + n) % n)) < (((p[1] - p[0] + n) % n))
                      ? (((p[0] - p[1] + n) % n))
                      : (((p[1] - p[0] + n) % n))));
  return 0;
}
