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