#include <bits/stdc++.h>
using namespace std;
signed long long tonum(string s) {
  stringstream in(s);
  signed long long x;
  in >> x;
  return x;
}
string tostr(signed long long n) {
  stringstream in;
  in << n;
  string x;
  in >> x;
  return x;
}
signed long long gcd(signed long long a, signed long long b) {
  while (1) {
    a = a % b;
    if (a == 0) return b;
    b = b % a;
    if (b == 0) return a;
  }
}
int main() {
  int N, x1, y1, x2, y2;
  cin >> N;
  cin >> x1 >> y1 >> x2 >> y2;
  int ret = x1 + y1 + x2 + y2;
  if ((x1 - y1) * (x2 - y2) >= 0) {
    ret = abs(x1 + y1 - (x2 + y2));
  }
  cout << min(ret, 4 * N - ret) << endl;
  return 0;
}
