#include <bits/stdc++.h>
using namespace std;
template <typename T>
void alert(const T& t) {
  cout << t << endl;
  exit(0);
}
const int INF64 = 4e18;
template <typename T>
void Dout(const T& t, const string& comment = "") {}
vector<unsigned long long> factorize(unsigned long long x) {
  vector<unsigned long long> factors;
  for (unsigned long long i = 2; i <= sqrt(x); i++) {
    while (x % i == 0) {
      factors.push_back(i);
      x /= i;
    }
  }
  if (x != 1) {
    factors.push_back(x);
  }
  return factors;
}
long long MID(long long l, long long r) { return (l + r) / 2; }
long long LSON(long long u) { return u * 2; }
long long RSON(long long u) { return u * 2 + 1; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long pw(long long x, long long y) {
  if (y == 0) return 1;
  if (y % 2 == 0) {
    return pw(x * x, y / 2);
  } else {
    return pw(x, y - 1) * x;
  }
}
int main() {
  {}
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (l == 1 && r == n) alert(0LL);
  long long whenGoRight_needRight = abs(pos - r) + (r != n);
  long long whenGoRight_needLeft = (l != 1 ? (r - l) + 1 : 0);
  long long whenGoLeft_needLeft = abs(pos - l) + (l != 1);
  long long whenGoLeft_needRight = (r != n ? (r - l) + 1 : 0);
  long long ans = min(whenGoLeft_needLeft + whenGoLeft_needRight,
                      whenGoRight_needLeft + whenGoRight_needRight);
  cout << ans << endl;
  return 0;
}
