#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, x1, x2, y1, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  double d = 0;
  if (y1 == n && y2 == n)
    d = abs(x1 - x2);
  else if (x1 == n && x2 == n)
    d = abs(y1 - y2);
  else if (abs(x2 - x1) == n)
    d = n + min(y1 + y2, n - y1 + n - y2);
  else if (abs(y2 - y1) == n)
    d = n + min(x1 + x2, n - x1 + n - x2);
  else
    d = abs(x1 - x2) + abs(y1 - y2);
  cout << int(d) << endl;
}
