#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long INF = LLONG_MAX;
const long long mod = 1000000007;
int main() {
  long long n, pos, l, r;
  cin >> n >> pos >> l >> r;
  long long ans, temp = 1;
  if (pos <= l) {
    if (r != n)
      ans = l - pos + min(temp, l - 1) + r - l + min(temp, n - r);
    else
      ans = l - pos + min(temp, l - 1);
  } else if (pos > l && pos < r) {
    if (l == 1) {
      if (n != r)
        ans = r - pos + min(temp, n - r);
      else
        ans = 0;
    } else {
      if (n != r) {
        ans = min(pos - l, r - pos) + r - l + 2;
      } else
        ans = 1 + pos - l;
    }
  } else if (pos >= r) {
    if (l != 1)
      ans = pos - r + min(temp, n - r) + r - l + 1;
    else
      ans = pos - r + min(temp, n - r);
  }
  cout << ans;
  return 0;
}
