#include <bits/stdc++.h>
using namespace std;
const int maxN = 1010;
int n, res, x_1, x_2, y_1, y_2, check[maxN][maxN];
struct ioi {
  int x, y;
};
ioi q[maxN * 10];
int main() {
  scanf("%d%d%d%d%d", &n, &x_1, &y_1, &x_2, &y_2);
  int l = 1, r = 1;
  q[1].x = x_1;
  q[1].y = y_1;
  check[x_1][y_1] = 1;
  while (l <= r) {
    ioi u = q[l++];
    if ((u.x == x_2) && (u.y == y_2)) {
      res = check[x_2][y_2];
      break;
    }
    if ((u.y == 0) || (u.y == n)) {
      ioi v = u;
      --v.x;
      if ((v.x >= 0) && (check[v.x][v.y] == 0))
        check[v.x][v.y] = check[u.x][u.y] + 1, q[++r] = v;
      v.x += 2;
      if ((v.x <= n) && (check[v.x][v.y] == 0))
        check[v.x][v.y] = check[u.x][u.y] + 1, q[++r] = v;
    }
    if ((u.x == 0) || (u.x == n)) {
      ioi v = u;
      --v.y;
      if ((v.y >= 0) && (check[v.x][v.y] == 0))
        check[v.x][v.y] = check[u.x][u.y] + 1, q[++r] = v;
      v.y += 2;
      if ((v.y <= n) && (check[v.x][v.y] == 0))
        check[v.x][v.y] = check[u.x][u.y] + 1, q[++r] = v;
    }
  }
  printf("%d", res - 1);
  fclose(stdin);
  fclose(stdout);
}
