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