#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";
    return 0;
  }
  if ((pos >= l) && (pos <= r)) {
    if (l == 1) {
      cout << r - pos + 1;
    } else if (r == n) {
      cout << pos - l + 1;
    } else {
      cout << min(r - pos, pos - l) + r - l + 2;
    }
  } else if (pos < l) {
    if (r == n) {
      cout << l - pos + 1;
    } else {
      cout << r - pos + 2;
    }
  } else if (pos > r) {
    if (l == 1) {
      cout << pos - r + 1;
    } else {
      cout << pos - l + 2;
    }
  }
}
