#include <bits/stdc++.h>
using namespace std;
float distance(long long x, long long y, long long a, long long b) {
  return sqrt((x - y) * (x - y) + (a - b) * (a - b));
}
int32_t main() {
  float n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if ((x1 == x2 && (x1 == n || x1 == 0)) ||
      (y1 == y2 && (y1 == 0 || y2 == n))) {
    cout << abs(x1 - x2) + abs(y1 - y2);
    return 0;
  }
  long long path1 = 0, path2 = 0;
  if (abs(x1 - x2) == n) {
    path1 = 2 * n - (y1 + y2);
    path2 = y1 + y2;
    cout << (path1 > path2 ? path2 : path1) + n;
    return 0;
  }
  if (abs(y1 - y2) == n) {
    path1 = 2 * n - (x1 + x2);
    path2 = x1 + x2;
    cout << (path1 > path2 ? path2 : path1) + n;
    return 0;
  }
  cout << abs(x1 - x2) + abs(y2 - y1);
}
