#include <bits/stdc++.h>
using namespace std;
template <class T>
inline vector<pair<T, int> > FACTORISE(T n) {
  vector<pair<T, int> > R;
  for (T i = 2; n > 1;) {
    if (n % i == 0) {
      int C = 0;
      for (; n % i == 0; C++, n /= i)
        ;
      R.push_back(make_pair(i, C));
    }
    i++;
    if (i > n / i) i = n;
  }
  if (n > 1) R.push_back(make_pair(n, 1));
  return R;
}
template <class T>
inline T TOTIENT(T n) {
  vector<pair<T, int> > R = FACTORISE(n);
  T r = n;
  for (int i = 0; i < R.size(); i++) r = r / R[i].first * (R[i].first - 1);
  return r;
}
struct state {
  int row, col, val;
  state(int _r, int _c, int _v) : row(_r), col(_c), val(_v) {}
  bool operator<(const state &s) const { return val > s.val; }
};
int n;
int dist(int x, int y) {
  if (y == 0) return x;
  if (x == n) return n + y;
  if (y == n) return (3 * n) - x;
  if (x == 0) return (4 * n) - y;
}
int main() {
  scanf("%d", &n);
  int x1, x2, y1, y2;
  scanf("%d", &x1);
  scanf("%d", &y1);
  scanf("%d", &x2);
  scanf("%d", &y2);
  int d1, d2;
  d1 = dist(x1, y1);
  d2 = dist(x2, y2);
  printf("%d\n", min(abs(d1 - d2), 4 * n - abs(d1 - d2)));
  return 0;
}
