#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
const long long MOD = 2e9 + 7;
int main() {
  int n, x1, y1, x2, y2;
  scanf("%d %d %d", &n, &x1, &y1);
  scanf("%d %d", &x2, &y2);
  int sum = x1 + x2 + y1 + y2;
  int a = abs(x1 - x2), b = abs(y1 - y2);
  if (a != n && b != n) sum = a + b;
  cout << min(sum, 4 * n - sum);
  return 0;
}
