#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
int a[4][2];
int n, x1, Y1, x2, y2;
void solve() {
  a[0][0] = 0, a[0][1] = 0;
  a[1][0] = n, a[1][1] = n;
  a[2][0] = n, a[2][1] = 0;
  a[3][0] = 0, a[3][1] = n;
  int ans = inf;
  if (abs(x1 - x2) == n || abs(Y1 - y2) == n) {
    for (int i = 0; i < 4; i++)
      ans = (ans < abs(x1 - a[i][0]) + abs(Y1 - a[i][1]) + abs(x2 - a[i][0]) +
                         abs(y2 - a[i][1])
                 ? ans
                 : abs(x1 - a[i][0]) + abs(Y1 - a[i][1]) + abs(x2 - a[i][0]) +
                       abs(y2 - a[i][1]));
  } else
    ans = abs(x1 - x2) + abs(Y1 - y2);
  cout << ans << endl;
}
int main() {
  int i, j, k;
  cin >> n >> x1 >> Y1 >> x2 >> y2;
  solve();
  return 0;
}
