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