#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  scanf("%d", &n);
  int x1, y1, x2, y2;
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  int xdist = abs(x1 - x2);
  int ydist = abs(y1 - y2);
  if (xdist == 0 && (x1 == 0 || x1 == n))
    printf("%d", ydist);
  else if (ydist == 0 && (y1 == 0 || y1 == n))
    printf("%d", xdist);
  else if (xdist == n) {
    int dist = xdist + min(y1 + y2, n - y1 + n - y2);
    printf("%d", dist);
  } else if (ydist == n)
    printf("%d", ydist + min(x1 + x2, n - x1 + n - x2));
  else
    printf("%d", xdist + ydist);
  return 0;
}
