#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main() {
  int n, id, l, r;
  cin >> n >> id >> l >> r;
  if (l == 1 && r == n)
    cout << "0\n";
  else if (l == 1)
    cout << abs(r - id) + 1 << '\n';
  else if (r == n)
    cout << abs(id - l) + 1 << '\n';
  else
    cout << r - l + min(abs(r - id), abs(id - l)) + 2 << '\n';
  return 0;
}
