#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
const int oo = 1000000000;
int main() {
  int n, x, l, r;
  cin >> n >> x >> l >> r;
  if (l == 1 && r == n) return cout << 0, 0;
  if (l == 1) return cout << abs(r - x) + 1, 0;
  if (r == n) return cout << abs(x - l) + 1, 0;
  cout << min(abs(r - x), abs(x - l)) + r - l + 2 << endl;
  return 0;
}
