#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p, l, r;
  cin >> n >> p >> l >> r;
  if (l == 1) {
    if (r == n) {
      cout << 0 << endl;
      return 0;
    }
    cout << abs(p - r) + 1 << endl;
    return 0;
  }
  if (r == n) {
    cout << abs(l - p) + 1 << endl;
    return 0;
  }
  if (p < l) {
    cout << abs(p - r) + 2 << endl;
    return 0;
  }
  if (l <= p and p <= r) {
    cout << abs(r - l) + min(p - l, r - p) + 2 << endl;
    return 0;
  }
  cout << p - l + 2 << endl;
  return 0;
}
