#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, l;
  cin >> n >> i >> j >> k >> l;
  int man = (abs(k - i) + abs(l - j));
  if (i == n && k == 0 || k == n && i == 0)
    cout << min(man + 2 * min(n - j, n - l), man + 2 * min(j, l));
  else if (j == n && l == 0 || l == n && j == 0)
    cout << min(man + 2 * min(n - k, n - i), man + 2 * min(k, i));
  else
    cout << man;
}
