#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, x2, y1, y2, n;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int distance = 0;
  while (x1 != x2 || y1 != y2) {
    ++distance;
    if (!x1 && y1 > 0)
      --y1;
    else if (y1 == 0 && x1 < n)
      ++x1;
    else if (x1 == n && y1 < n)
      ++y1;
    else
      --x1;
  }
  cout << min(distance, -distance + (n << 2));
  return 0;
}
