#include <bits/stdc++.h>
using namespace std;
long long mod = (pow(10, 9) + 7);
long long MAXX = 3000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, pos, a, b;
  cin >> n >> pos >> a >> b;
  long long ans = 0;
  if (a > 1 && b < n && pos <= b && pos >= a) {
    long long first = min(pos - a, b - pos);
    ans = first + 1 + (b - a) + 1;
    cout << ans << endl;
    return 0;
  } else if (a > 1 && b < n) {
    ans = min(abs(pos - a), abs(pos - b)) + (b - a) + 1 + 1;
    cout << ans << endl;
    return 0;
  }
  if (pos < a) {
    ans += (a - pos);
    pos = a;
  }
  if (pos > b) {
    ans += (pos - b);
    pos = b;
  }
  if (a > 1) ans += (pos - a) + 1;
  if (b < n) ans += (b - pos) + 1;
  cout << ans << endl;
  return 0;
}
