#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (abs(x1 - x2) == n)
    cout << n + min(2 * n - (y1 + y2), y1 + y2) << endl;
  else if (abs(y1 - y2) == n)
    cout << n + min(2 * n - (x1 + x2), x1 + x2);
  else
    cout << abs(x1 - x2) + abs(y1 - y2) << endl;
  return 0;
}
