#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
using namespace std;
int main() {
  long long n, pos, l, r;
  scanf("%lld %lld %lld %lld", &n, &pos, &l, &r);
  if (l == 1 and n == r)
    cout << "0" << endl;
  else if (l == 1) {
    cout << llabs(r - pos) + 1 << endl;
  } else if (n == r) {
    cout << llabs(l - pos) + 1 << endl;
  } else {
    cout << llabs(r - l) + 2 + min(llabs(l - pos), llabs(r - pos)) << endl;
  }
  return 0;
}
