#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, px1, py1, px2, py2;
  cin >> n >> px1 >> py1 >> px2 >> py2;
  if (abs(px1 - px2) < n && abs(py1 - py2) < n)
    cout << abs(px1 - px2) + abs(py1 - py2);
  else if (abs(px1 - px2) == n)
    cout << n + min(py1 + py2, abs(n - py1) + abs(n - py2));
  else if (abs(py1 - py2) == n)
    cout << n + min(px1 + px2, abs(n - px1) + abs(n - px2));
  return 0;
}
