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