#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fast_exp(int base, int expo) {
  long long res = 1;
  while (expo > 0) {
    if (expo & 1) {
      res = (res * base) % mod;
    }
    base = (base * base) % mod;
    expo >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  int t1 = r - l;
  int steps = 0;
  if (pos < l) {
    steps = t1 + (l - pos);
    steps += 2;
    if (r == n) {
      steps--;
      steps -= t1;
    }
  } else if (pos > r) {
    steps = t1 + (pos - r);
    steps += 2;
    if (l == 1) {
      steps--;
      steps -= t1;
    }
  } else {
    if (l == 1 && r == n) {
      steps = 0;
    } else if (l == 1) {
      steps = r - pos;
      steps++;
    } else if (r == n) {
      steps = pos - l;
      steps++;
    } else {
      steps = t1 + min(pos - l, r - pos);
      steps += 2;
    }
  }
  cout << steps;
  return 0;
}
