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