#include <bits/stdc++.h>
using namespace std;
int n, x1, y_1, x2, y2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x1 >> y_1 >> x2 >> y2;
  int ans;
  if ((y2 == 0 && y_1 == 0) || (y2 == n && y_1 == n)) {
    cout << fabs(x1 - x2);
    return 0;
  } else if ((x2 == 0 && x1 == 0) || (x2 == n && x1 == n)) {
    cout << fabs(y_1 - y2);
    return 0;
  } else {
    if (x1 == 0 && y_1 <= n) {
      if (x2 == n && y2 != 0) ans = y_1 + n + y2;
      if (x2 != 0 && y2 == 0) ans = y_1 + x2;
      if (x2 != 0 && y2 == n) ans = n - y_1 + x2;
    }
    if (x1 != 0 && y_1 == n) {
      if (x2 == n && y2 != 0) ans = n - y2 + n - x1;
      if (x2 != 0 && y2 == 0) ans = n + x2 + x1;
      if (x2 == 0 && y2 != 0) ans = n - y2 + x1;
    }
    if (x1 == n && y_1 != 0) {
      if (x2 != 0 && y2 == n) ans = n - y_1 + n - x2;
      if (x2 != 0 && y2 == 0) ans = n - x2 + y_1;
      if (x2 == 0 && y2 != 0) ans = y2 + n + y_1;
    }
    if (x1 != 0 && y_1 == 0) {
      if (x2 == n && y2 != 0) ans = y2 + n - x1;
      if (x2 == 0 && y2 != 0) ans = x1 + y2;
      if (x2 != 0 && y2 == n) ans = x2 + n + x1;
    }
  }
  cout << min(ans, 4 * n - ans);
  return 0;
}
