#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int ans = 0;
  if (x1 == 0 || x1 == n)
    if (x1 == x2) {
      cout << abs(y1 - y2) << endl;
      return 0;
    }
  if (y1 == 0 || y1 == n)
    if (y1 == y2) {
      cout << abs(x1 - x2) << endl;
      return 0;
    }
  if (abs(x1 - x2) < n && abs(y1 - y2) < n) {
    cout << abs(x1 - x2) + abs(y1 - y2) << endl;
    return 0;
  }
  if (abs(x1 - x2) == n) {
    int yp1 = 0;
    yp1 = min(y1 + y2, 2 * n - y1 - y2);
    cout << yp1 + n << endl;
    return 0;
  }
  if (abs(y1 - y2) == n) {
    int xp1 = 0;
    xp1 = min(x1 + x2, 2 * n - x1 - x2);
    cout << xp1 + n << endl;
    return 0;
  }
}
