#include <bits/stdc++.h>
using namespace std;
int n, x1, yy1, x2, y2;
int main() {
  while (scanf("%d %d %d %d %d", &n, &x1, &yy1, &x2, &y2) == 5) {
    int a = 0, b = 0, s1, s2;
    if (y2 == 0) {
      a = x2;
      s1 = 3;
    } else if (x2 == 0) {
      a = y2;
      s1 = 0;
    } else if (y2 == n) {
      a = x2;
      s1 = 1;
    } else if (x2 == n) {
      a = y2;
      s1 = 2;
    }
    if (yy1 == 0) {
      b = x1;
      s2 = 3;
    } else if (x1 == 0) {
      b = yy1;
      s2 = 0;
    } else if (yy1 == n) {
      b = x1;
      s2 = 1;
    } else if (x1 == n) {
      b = yy1;
      s2 = 2;
    }
    int r;
    if (s1 == s2) {
      r = max(b, a) - min(b, a);
    } else {
      if ((s1 == 0 && s2 == 1) || (s1 == 1 && s2 == 0) ||
          (s1 == 2 && s2 == 3) || (s1 == 3 && s2 == 2)) {
        if (s1 == 0 || s1 == 3) {
          r = (n - a) + b;
        } else {
          r = (n - b) + a;
        }
      } else if ((s1 == 0 && s2 == 3) || (s1 == 3 && s2 == 0)) {
        r = a + b;
      } else if ((s1 == 0 && s2 == 2) || (s1 == 2 && s2 == 0) ||
                 (s1 == 1 && s2 == 3) || (s1 == 3 && s2 == 1)) {
        r = n + min(a + b, ((2 * n) - a - b));
      } else if ((s1 == 1 && s2 == 2) || (s1 == 2 && s2 == 1)) {
        r = (2 * n) - a - b;
      }
    }
    printf("%d\n", r);
  }
  return 0;
}
