#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int a[maxn];
int pos, l, r, n;
int main(void) {
  cin >> n >> pos >> l >> r;
  if (l > 1 && r < n) {
    cout << min(abs(pos - l), abs(pos - r)) + r - l + 2;
  } else if (l == 1 && r == n) {
    cout << 0;
  } else if (l > 1) {
    cout << abs(pos - l) + 1;
  } else {
    cout << abs(pos - r) + 1;
  }
  return 0;
}
