#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, y1, x2, y2;
  int i, j, k, l;
  scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);
  int ans = 0;
  int mn = 10000000;
  int ok = 0;
  if ((y1 == 0 && y2 == 0) || (y1 == n && y2 == n)) {
    printf("%d\n", abs(x1 - x2));
    return 0;
  }
  if (abs(x1 - x2) == n) {
    ans = n - y1 + n + (n - y2);
    mn = min(ans, mn);
    ans = y1 + n + y2;
    mn = min(ans, mn);
  }
  if (abs(y1 - y2) == n) {
    ans = n - x1 + n + (n - x2);
    mn = min(ans, mn);
    ans = x1 + n + x2;
    mn = min(ans, mn);
  } else {
    if (abs(x1 - x2) > 0) {
      if (y1 == n || y2 == n) {
        if (x1 == 0) mn = n - y1 + x2;
        if (x2 == 0) mn = n - y2 + x1;
        if (x1 == n) mn = n - y1 + (n - x2);
        if (x2 == n) mn = n - y2 + (n - x1);
      }
      if (y1 == 0 || y2 == 0) {
        if (x1 == 0) mn = y1 + x2;
        if (x2 == 0) mn = y2 + x1;
        if (x1 == n) mn = y1 + (n - x2);
        if (x2 == n) mn = y2 + (n - x1);
      }
    } else {
      mn = abs(y1 - y2);
    }
  }
  printf("%d\n", mn);
  return 0;
}
