#include <bits/stdc++.h>
using namespace std;
void answer() {
  long long n, m, ans = 0, x1, x2, y1, y2, ans1;
  cin >> n >> x1 >> x2 >> y1 >> y2;
  std::vector<pair<long long, long long>> v;
  for (int i = 0; i <= n; i++) v.push_back({i, 0});
  for (int i = 1; i <= n; i++) v.push_back({n, i});
  for (int i = 1; i <= n; i++) v.push_back({n - i, n});
  for (int i = 1; i <= n - 1; i++) v.push_back({0, n - i});
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first == x1 && v[i].second == x2) ans = i;
    if (v[i].first == y1 && v[i].second == y2) ans1 = i;
  }
  cout << min(abs(ans1 - ans), 4 * n - abs(ans1 - ans));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  answer();
  return 0;
}
