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