#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma warning(disable : 4996)
#pragma warning(disable : 4018)
using namespace std;
typedef long long ll;
typedef unsigned long long uint64;
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T isprime(T n) {
  if (n <= 1) return false;
  for (T i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
template <class T>
void stoset(string s, set<T> &res_set) {
  res_set.clear();
  istringstream sin(s);
  for (T v; sin >> v; res_set.insert(v))
    ;
}
ll dis(ll x1, ll y1, ll x2, ll y2) {
  return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double dist(double x1, double y1, double x2, double y2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
double distR(double x1, double y1, double x2, double y2) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
int main() {
  ll n, x1, y1, x2, y2, value;
  while (cin >> n >> x1 >> y1 >> x2 >> y2) {
    if ((x1 > y1) == (x2 > y2)) {
      value = abs(x1 - x2) + abs(y1 - y2);
    } else {
      value = x1 + y1 + x2 + y2;
      if (4 * n - value < value) {
        value = 4 * n - value;
      }
    }
    cout << value << endl;
  }
  return 0;
}
