#include <bits/stdc++.h>
using namespace std;
long double pi = 3.1415926536;
long long mod = 1000000007;
vector<long long> a[1000000];
vector<long long> vis(1000000, false);
long long b[1000000] = {0}, d[1000000] = {0};
void dfs(long long x) {
  if (vis[x]) return;
  vis[x] = true;
  for (auto c : a[x]) {
    dfs(c);
  }
}
queue<long long> q;
stack<long long> s;
void bfs(long long x) {
  q.push(x);
  s.push(x);
  vis[x] = true;
  b[x] = -1;
  while (!q.empty()) {
    long long p = q.front();
    q.pop();
    for (auto c : a[p]) {
      if (!vis[c]) {
        q.push(c);
        vis[c] = true;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x1, y1, x2, y2, c;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int r = abs(x2 - x1), s = abs(y2 - y1);
  if (r == n || s == n)
    c = x1 + x2 + y1 + y2;
  else
    c = r + s;
  cout << min(c, 4 * n - c);
}
