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