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