#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, p, l, r;
  cin >> n >> p >> l >> r;
  int sec = 0;
  int a = 0;
  int b = 0;
  if (l == 1) {
    if (r == n) {
      cout << 0;
      exit(0);
    }
    sec = abs(r - p);
    sec++;
  } else if (r == n) {
    sec = abs(p - l);
    sec++;
  } else {
    sec = r - l;
    sec += 2;
    sec += min(abs(p - l), abs(r - p));
  }
  cout << sec;
}
