#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 << endl;
  else if (l == 1 & r != n) {
    if (l <= pos & pos <= r)
      cout << r - pos + 1 << endl;
    else
      cout << pos - r + 1 << endl;
  } else if (r == n & l != 1) {
    if (l <= pos & pos <= r)
      cout << pos - l + 1 << endl;
    else
      cout << l - pos + 1 << endl;
  } else {
    if (l <= pos & pos <= r) {
      if ((pos - l) < (r - pos))
        cout << pos + r - 2 * l + 2 << endl;
      else if ((pos - l) >= (r - pos))
        cout << 2 * r - pos + 2 - l << endl;
    } else {
      if (pos < l)
        cout << r + 2 - pos << endl;
      else if (pos > r)
        cout << pos + 2 - l << endl;
    }
  }
}
