#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, l, r;
  scanf("%d", &n);
  scanf("%d", &p);
  scanf("%d", &l);
  scanf("%d", &r);
  if (l == 1 && r == n)
    printf("%d", 0);
  else {
    if (l != 1 && r == n) {
      int f = abs(p - l) + 1;
      printf("%d", f);
    } else {
      if (l == 1 && r != n) {
        int f = abs(p - r) + 1;
        printf("%d", f);
      } else {
        int k = abs(p - l);
        int b = abs(p - r);
        int f = r - l + min(k, b) + 2;
        printf("%d", f);
      }
    }
  }
  return 0;
}
