#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int main() {
  while (scanf("%d %d %d %d %d", &n, &a, &b, &c, &d) != EOF) {
    int f1 = 0, f2 = 0;
    if (a >= b) f1 = 1;
    if (c >= d) f2 = 1;
    int ans = 0;
    if (f1 + f2 == 1) {
      int t1 = a + b;
      int t2 = c + d;
      int t11 = (2 * n) - t1;
      int t22 = (2 * n) - t2;
      ans = min(t1 + t2, t11 + t22);
    } else {
      int t1 = a + b;
      int t2 = c + d;
      ans = abs(t1 - t2);
    }
    printf("%d\n", ans);
  }
  return 0;
}
