#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  p--;
  int pn = p;
  int l, r;
  cin >> l >> r;
  l--;
  r--;
  int ans = 0;
  if (l != 0) {
    ans += abs(p - l);
    p = l;
    ans++;
  }
  if (r != n - 1) {
    ans += abs(r - p);
    ans++;
  }
  int add = 0;
  p = pn;
  if (r != n - 1) {
    add += abs(r - p);
    add++;
    p = r;
  }
  if (l != 0) {
    add += abs(p - l);
    add++;
  }
  ans = min(ans, add);
  cout << ans << endl;
  return 0;
}
