#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return 0;
  else
    return gcd(b, a % b);
}
int powmod(int base, int exp) {
  if (exp == 0)
    return 1;
  else if (exp == 1)
    return base;
  else {
    int ans = base;
    while (exp > 1) {
      ans = ans * ans;
      if (exp & 1) ans *= base;
      ans %= 1000000009;
      exp /= 2;
    }
    return ans;
  }
}
int main() {
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  int count = 0;
  count += n - r + l - 1;
  if (r == n && l == 1)
    cout << 0 << endl;
  else if (r == n) {
    cout << abs(pos - l) + 1 << endl;
  } else if (l == 1) {
    cout << abs(r - pos) + 1 << endl;
  } else {
    if (pos <= l) {
      cout << l - pos + r - l + 2 << endl;
    } else if (pos >= r) {
      cout << pos - r + r - l + 2 << endl;
    } else {
      cout << r - l + min(pos - l, r - pos) + 2 << endl;
    }
  }
  return 0;
}
