#include <bits/stdc++.h>
using namespace std;
long long n;
long long x1, yy1, x2, y2;
vector<pair<long long, long long>> child(long long a, long long b) {
  long long arr[] = {1, -1};
  vector<pair<long long, long long>> v;
  if (a == 0 || a == n)
    for (long long i = 0; i < 2; i++) {
      if (b + arr[i] <= n && b + arr[i] >= 0)
        v.push_back(make_pair(a, b + arr[i]));
    }
  else
    for (long long i = 0; i < 2; i++) {
      if (a + arr[i] <= n && a + arr[i] >= 0)
        v.push_back(make_pair(a + arr[i], b));
    }
  if (v.size() == 1) {
    if (a == 0) v.push_back(make_pair(1, b));
    if (a == n) v.push_back(make_pair(n - 1, b));
  }
  return v;
}
signed main() {
  cin >> n;
  cin >> x1 >> yy1 >> x2 >> y2;
  map<pair<long long, long long>, long long> d;
  map<pair<long long, long long>, long long> vis;
  queue<pair<long long, long long>> q;
  q.push(make_pair(x1, yy1));
  d[make_pair(x1, yy1)] = 0;
  vis[make_pair(x1, yy1)] = 1;
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    vector<pair<long long, long long>> ch = child(p.first, p.second);
    for (long long i = 0; i < ch.size(); i++) {
      if (vis[ch[i]] == 0) {
        vis[ch[i]] = 1;
        q.push(ch[i]);
        d[ch[i]] = d[p] + 1;
      }
    }
  }
  cout << d[make_pair(x2, y2)];
}
