#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  long long int rc, lc;
  rc = n - r;
  lc = l - 1;
  long long int t = 0;
  if (rc != 0 || lc != 0) {
    if (rc == 0) {
      t += abs(pos - l);
      t += 1;
    } else if (lc == 0) {
      t += abs(pos - r);
      t += 1;
    } else {
      if (abs(pos - r) < abs(pos - l)) {
        t += abs(pos - r);
        t += 1;
        t += r - l;
        t += 1;
      } else {
        t += abs(pos - l);
        t += 1;
        t += r - l;
        t += 1;
      }
    }
  }
  cout << t;
}
