#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = acos(-1.0);
const int inf = (int)1e9;
const double eps = 1e-6;
const int ss = (int)1e6 + 3;
const int base = inf;
bool pred(const pair<int, int>& i, const pair<int, int>& j) {
  if (i.first == j.first) {
    return i.second > j.second;
  } else {
    return i.first > j.first;
  }
}
char c[3][3];
int main() {
  int n;
  int x1, x2, y1, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int res = 0;
  if ((x1 < y1) == (x2 < y2)) {
    res = abs(x1 - x2) + abs(y1 - y2);
  } else {
    res = x1 + y1 + x2 + y2;
    res = min(res, n * 4 - res);
  }
  cout << res;
  return 0;
}
