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