#include <bits/stdc++.h>
using namespace std;
int n, x1, x2, yy1, yy2, t;
int newCor(int x, int y) {
  if (x == 0) return y;
  if (y == n) return n + x;
  if (x == n) return 2 * n + (n - y);
  return 3 * n + (n - x);
}
int main() {
  cin >> n >> x1 >> yy1 >> x2 >> yy2;
  cout << min(t, n * 4 - (t = abs(newCor(x1, yy1) - newCor(x2, yy2))));
  return 0;
}
