#include <bits/stdc++.h>
const int N = 1e9 + 7;
const int M = 1e6 + 5;
using namespace std;
int main() {
  int n, b, c, d, e, f;
  while (~scanf("%d%d%d%d", &n, &b, &c, &d)) {
    if (c == 1 && d == n) {
      printf("0\n");
      continue;
    }
    if (c == 1) {
      e = abs(d - b) + 1;
      printf("%d\n", e);
      continue;
    }
    if (d == n) {
      e = abs(c - b) + 1;
      printf("%d\n", e);
      continue;
    }
    e = abs(c - b) + abs(d - c) + 2;
    f = abs(d - b) + abs(c - d) + 2;
    e = min(e, f);
    printf("%d\n", e);
  }
  return 0;
}
