#include <bits/stdc++.h>
int main() {
  int i, j, n, k, max, pos, l, r, ans;
  scanf("%d %d %d %d", &n, &pos, &l, &r);
  if (l == 1 && r == n) {
    printf("0");
  } else {
    if (l == r) {
      ans = abs(pos - l);
      if (l == 1 || l == n) {
        printf("%d", ans + 1);
      } else {
        printf("%d", ans + 2);
      }
    } else if (l == 1) {
      ans = abs(pos - r);
      printf("%d", ans + 1);
    } else if (r == n) {
      ans = abs(pos - l);
      printf("%d", ans + 1);
    } else {
      if (abs(pos - l) >= abs(pos - r)) {
        ans = abs(pos - r);
        ans += abs(r - l);
      } else {
        ans = abs(pos - l);
        ans += abs(r - l);
      }
      printf("%d", ans + 2);
    }
  }
  return 0;
}
