#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 10, mod = 1e9 + 7;
inline void smin(int &a, int b) {
  if (a > b) a = b;
}
int main() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int ans = 1e9;
  if (x1 == x2 && (x1 == 0 || x1 == n)) smin(ans, abs(y1 - y2));
  if (y1 == y2 && (y1 == 0 || y1 == n)) smin(ans, abs(x1 - x2));
  smin(ans, x1 + y1 + x2 + y2);
  smin(ans, 4 * n - (x1 + y1 + x2 + y2));
  smin(ans, abs(x1 - n) + y1 + abs(x2 - n) + y2);
  smin(ans, 4 * n - (x1 + y1 + x2 + y2));
  smin(ans, x1 + abs(y1 - n) + x2 + abs(y2 - n));
  smin(ans, 4 * n - (x1 + abs(y1 - n) + x2 + abs(y2 - n)));
  smin(ans, abs(x1 - n) + abs(x2 - n) + abs(y1 - n) + abs(y2 - n));
  smin(ans, 4 * n - (abs(x1 - n) + abs(x2 - n) + abs(y1 - n) + abs(y2 - n)));
  printf("%d\n", ans);
}
