#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int main() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int res = 0;
  int x = 0, y = 0;
  bool bol = 0;
  int d = 0;
  int dx, dy;
  while (1) {
    dx = dir[d][0];
    dy = dir[d][1];
    x += dx;
    y += dy;
    res += bol;
    if (x == x1 && y == y1) bol = 1;
    if (bol && x == x2 && y == y2) break;
    if (y > n) {
      y--;
      d++;
      d %= 4;
      res -= bol;
      continue;
    }
    if (x > n) {
      x--;
      d++;
      d %= 4;
      res -= bol;
      continue;
    }
    if (y < 0) {
      y++;
      d++;
      d %= 4;
      res -= bol;
      continue;
    }
    if (x < 0) {
      x++;
      d++;
      d %= 4;
      res -= bol;
      continue;
    }
  }
  cout << min(res, 4 * n - res) << endl;
}
