#include <bits/stdc++.h>
using namespace std;
const int magicconst = 1e7;
const long long mod = 1e9 + 7;
const int MAXN = 1e5 + 1;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a + b;
}
void Solve() {
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (l == 1 && r == n) {
    cout << 0 << endl;
    return;
  }
  if (l == 1) {
    cout << abs(pos - r) + 1 << endl;
    return;
  }
  if (r == n) {
    cout << abs(pos - l) + 1 << endl;
    return;
  }
  cout << min(abs(pos - l), abs(pos - r)) + 2 + abs(l - r) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  Solve();
  bool f = true;
}
