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