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