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