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