#include <bits/stdc++.h>
using namespace std;
int n, x, y, x2, y2;
int Poisk1() {
  if ((x == x2 && (x == n || x == 0)) || (y == y2 && (y == n || y == 0)))
    return fabs(y - y2) + fabs(x - x2);
  else if ((y == 0 && y2 != n) || (y2 == 0 && y != n) || (y != 0 && y2 == n) ||
           (y2 != 0 && y == n))
    return fabs(y - y2) + fabs(x - x2);
  else if ((x == 0 && x2 == n) || (x2 == 0 && x == n))
    return y + y2 + n;
  else if ((y == 0 && y2 == n) || (y2 == 0 && y == n))
    return x + x2 + n;
}
int Poisk2() {
  if ((x == x2 && (x == n || x == 0)) || (y == y2 && (y == n || y == 0)))
    return fabs(y - y2) + fabs(x - x2);
  else if ((y == 0 && y2 != n) || (y2 == 0 && y != n) || (y != 0 && y2 == n) ||
           (y2 != 0 && y == n))
    return fabs(y - y2) + fabs(x - x2);
  else if ((x == 0 && x2 == n) || (x2 == 0 && x == n))
    return 3 * n - y - y2;
  else if ((y == 0 && y2 == n) || (y2 == 0 && y == n))
    return 3 * n - x - x2;
}
int main() {
  cin >> n >> x >> y >> x2 >> y2;
  if (Poisk1() < Poisk2())
    cout << Poisk1();
  else
    cout << Poisk2();
  return 0;
}
