#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, x1, x2, y1, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (n < 1 || n > 1000 || x1 > n || x1 < 0 || x2 > n || x2 < 0 || y1 > n ||
      y1 < 0 || y2 > n || y2 < 0)
    return 0;
  else {
    if (abs(x2 - x1) == n)
      t = n + y1 + y2;
    else if (abs(y2 - y1) == n)
      t = n + x1 + x2;
    else
      t = abs(y2 - y1) + abs(x2 - x1);
    if (t > 2 * n)
      cout << 4 * n - t << endl;
    else
      cout << t << endl;
  }
  return 0;
}
