#include <bits/stdc++.h>
int main() {
  int n, a, b, c, d, x;
  std::cin >> n >> a >> b >> c >> d;
  if (!a) b = -b;
  if (b == n) b = -b, a = -a;
  if (!c) d = -d;
  if (d == n) d = -d, c = -c;
  x = abs(a + b - c - d);
  std::cout << std::min(x, 4 * n - x);
}
