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