#include <bits/stdc++.h>
using namespace std;
int n;
bool onSq(int x, int y) {
  if ((x == 0 || x == n) && y >= 0 && y <= n) return true;
  if ((y == 0 || y == n) && x >= 0 && x <= n) return true;
  return false;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int i, j;
  int x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int res = 0;
  int cd = 0;
  int ox, oy;
  ox = x1, oy = y1;
  while (x1 != x2 || y1 != y2) {
    int nx, ny;
    while (1) {
      nx = x1 + dx[cd];
      ny = y1 + dy[cd];
      if (onSq(nx, ny) && (nx != ox || ny != oy)) break;
      cd = (cd + 1) % 4;
    }
    ox = x1;
    oy = y1;
    x1 = nx;
    y1 = ny;
    ++res;
  }
  cout << min(res, 4 * n - res) << endl;
  return 0;
}
