#include <bits/stdc++.h>
using namespace std;
void mahakal() {}
const int maxN = 2e5 + 5, N = 1e2 + 5;
long long n, pos, l, r;
void solve() {
  cin >> n >> pos >> l >> r;
  long long ans = 1e10;
  long long ps = 0;
  if (l != 1) {
    ps = abs(pos - l) + 1;
    if (r != n) {
      ps += abs(r - l) + 1;
    }
  } else {
    if (r != n) ps = abs(r - pos) + 1;
  }
  ans = min(ans, ps);
  ps = 0;
  if (r != n) {
    ps = abs(r - pos) + 1;
    if (l != 1) ps += abs(l - r) + 1;
  } else {
    if (l != 1) ps = abs(pos - l) + 1;
  }
  ans = min(ans, ps);
  cout << ans << endl;
}
int main() {
  mahakal(), ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
  return 0;
}
