#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x1, y1, x2, y2, c;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  long long int r = abs(x2 - x1), s = abs(y2 - y1);
  if (r == n || s == n)
    c = x1 + x2 + y1 + y2;
  else
    c = r + s;
  cout << min(c, 4 * n - c);
}
