#include <bits/stdc++.h>
using namespace std;
int minPath(int n, int x1, int y1, int x2, int y2) {
  if ((x1 <= x2 && y1 <= y2) || (x1 >= x2 && y1 >= y2)) {
    if (!(abs(y2 - y1) == n || abs(x2 - x1) == n))
      return (abs(x1 - x2) + abs(y1 - y2));
  }
  return min(x1 + x2 + y1 + y2, (4 * n) - (x1 + x2 + y1 + y2));
}
int main() {
  int n, x1, x2, y1, y2, d1, d2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  cout << minPath(n, x1, y1, x2, y2);
  return 0;
}
