#include <bits/stdc++.h>
using namespace std;
int main() {
  map<pair<int, int>, vector<pair<int, int>>> m;
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  for (int i = 0; i < n; i++) {
    m[{i, 0}].push_back({i + 1, 0});
    m[{i + 1, 0}].push_back({i, 0});
    m[{0, i}].push_back({0, i + 1});
    m[{0, i + 1}].push_back({0, i});
    m[{i, n}].push_back({i + 1, n});
    m[{i + 1, n}].push_back({i, n});
    m[{n, i}].push_back({n, i + 1});
    m[{n, i + 1}].push_back({n, i});
  }
  map<pair<int, int>, int> visit;
  stack<pair<int, int>> q;
  q.push({a, b});
  int f = 1, nn = 0, tt = 0, one = 0, two = 0;
  if (a == c && b == d)
    cout << "0\n";
  else {
    while (q.size()) {
      int a = q.top().first;
      int b = q.top().second;
      q.pop();
      visit[{a, b}] = 1;
      for (auto it = m[{a, b}].begin(); it != m[{a, b}].end(); it++) {
        if (visit[{it->first, it->second}] == 0) {
          if (one == 1) {
            if (it->first == c && it->second == d) {
              tt++;
              f = 0;
              break;
            } else {
              q.push({it->first, it->second});
              visit[{it->first, it->second}] = 1;
              tt++;
            }
          }
          one = 1;
        }
      }
      if (f == 0) break;
    }
    cout << min(tt, 4 * n - tt) << "\n";
  }
}
