#include <bits/stdc++.h>
using namespace std;
int _I() {
  int x;
  scanf("%d", &x);
  return x;
}
long long int _L() {
  long long int x;
  scanf("%lld", &x);
  return x;
}
int main() {
  int n = _I(), pos = _I(), l = _I(), r = _I();
  if (l == 1 && r == n) {
    cout << "0";
    return 0;
  }
  int ans = 0;
  if (l == 1)
    ans = abs(pos - r) + 1;
  else if (r == n)
    ans = abs(pos - l) + 1;
  else {
    int m = min(abs(pos - r), abs(pos - l));
    ans = m + 2 + abs(r - l);
  }
  cout << ans;
  return 0;
}
