#include <bits/stdc++.h>
using namespace std;
int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a > b) return gcd(b, a % b);
  return gcd(a, b % a);
}
int main() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int r = 0;
  while (x1 != x2 || y1 != y2) {
    if (x1 == 0) {
      if (y1 < n)
        y1++;
      else
        x1 = 1;
    } else if (y1 == n) {
      if (x1 < n)
        x1++;
      else
        y1 = n - 1;
    } else if (x1 == n) {
      if (y1 > 0)
        y1--;
      else
        x1 = n - 1;
    } else {
      if (x1 > 0)
        x1--;
      else
        y1 = 1;
    }
    r++;
  }
  cout << min(r, 4 * n - r);
  return 0;
}
