#include <bits/stdc++.h>
using namespace std;
int n, x1, x2, y, y2;
int main() {
  cin >> n >> x1 >> y >> x2 >> y2;
  if ((x1 == 0 && x2 == 0) || (x1 == n && x2 == n)) {
    cout << abs(y - y2);
  } else if ((y == 0 && y2 == 0) || (y == n && y2 == n)) {
    cout << abs(x1 - x2);
  } else if ((x1 == 0 && y2 == n) || (x1 == n && y2 == 0) ||
             (x2 == 0 && y == n) || (x2 == n && y == 0)) {
    cout << abs(x1 - x2) + abs(y - y2);
  } else if (abs(x1 - x2) == n &&
             ((y != 0 && y != n) || (y2 != 0 && y2 != n))) {
    cout << min(y + y2, n - y + n - y2) + n;
  } else if (abs(y - y2) == n &&
             ((x1 != 0 && x1 != n) || (x2 != 0 && x2 != n))) {
    cout << min(x1 + x2, n - x1 + n - x2) + n;
  } else if ((x1 == 0 && x2 == n) || (x1 == n && x2 == 0))
    cout << n * 2;
  else if ((y == 0 && y2 == n) || (y == n && y2 == 0))
    cout << n * 2;
  else if (x1 == 0 && y2 == 0) {
    cout << x2 + y;
  } else if (x2 == 0 && y == 0) {
    cout << x1 + y2;
  } else if (x1 == n && y2 == n) {
    cout << n - x2 + n - y;
  } else if (x2 == n && y == n) {
    cout << n - x1 + n - y2;
  }
  return 0;
}
