#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, x1, y1;
  cin >> n >> x >> y >> x1 >> y1;
  if ((x >= y && x1 >= y1) || (x <= y && x1 <= y1)) {
    int c = abs(x - x1) + abs(y - y1);
    cout << c;
  } else {
    int c = min((x + x1 + y + y1), (4 * n - x - x1 - y - y1));
    cout << c;
  }
  return 0;
}
