#include <bits/stdc++.h>
using namespace std;
string itoa(long long a) {
  string ret;
  for (long long i = a; i > 0; i = i / 10) ret += ((i % 10) + 48);
  reverse(ret.begin(), ret.end());
  return ret;
}
int toi(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long toi64(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double tod(string s) {
  double r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
vector<string> token(string a, string b) {
  const char *q = a.c_str();
  while (count(b.begin(), b.end(), *q)) q++;
  vector<string> oot;
  while (*q) {
    const char *e = q;
    while (*e && !count(b.begin(), b.end(), *e)) e++;
    oot.push_back(string(q, e));
    q = e;
    while (count(b.begin(), b.end(), *q)) q++;
  }
  return oot;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T power(T x, T p) {
  if (!p) return 1;
  return x * power(x, p - 1);
}
const int mx = 0;
inline int in(int &a) { return scanf("%d", &a); }
inline int in(long long &a) { return scanf("%lld", &a); }
inline int in(double &a) { return scanf("%lf", &a); }
inline int in(char *a) { return scanf("%s", a); }
inline int in(unsigned long long &a) { return scanf("%llu", &a); }
int n;
int find(int a, int b) {
  if (a >= 0 && a <= n && b == 0) return 1;
  if (a == n && b >= 0 && b <= n) return 2;
  if (a >= 0 && a <= n && b == n) return 3;
  return 4;
}
int main() {
  int x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int a = find(x1, y1);
  int b = find(x2, y2);
  if (a == b)
    cout << abs(x1 - x2) + abs(y1 - y2) << endl;
  else {
    if (a > b) {
      swap(a, b);
      swap(x1, x2);
      swap(y1, y2);
    }
    if (abs(a - b) == 2) {
      if (a == 1 && b == 3)
        cout << min(n - x1 + n - x2, x1 + x2) + n << endl;
      else
        cout << min(n - y1 + n - y2, y1 + y2) + n << endl;
    } else {
      if (a == 1 && b == 2)
        cout << (n - x1) + y2 << endl;
      else if (a == 2 && b == 3)
        cout << (n - y1) + (n - x2) << endl;
      else if (a == 3 && b == 4)
        cout << x1 + (n - y2) << endl;
      else
        cout << x1 + y2 << endl;
    }
  }
  return 0;
}
