#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int powe(long long int a, long long int b) {
  long long int x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      x %= MOD;
    }
    y = (y * y);
    y %= MOD;
    b /= 2;
  }
  return x;
}
int main() {
  int n;
  int pos;
  int l, r;
  cin >> n >> pos >> l >> r;
  int ans = 0;
  if (pos >= l && pos <= r) {
    int res1 = 0;
    int res2 = 0;
    int p = pos;
    if (l > 1) {
      res1 += p - l + 1;
      p = l;
    }
    if (r < n) {
      res1 += r - p + 1;
      p = r;
    }
    p = pos;
    if (r < n) {
      res2 += r - p + 1;
      p = r;
    }
    if (l > 1) {
      res2 += p - l + 1;
      p = l;
    }
    ans = min(res1, res2);
  } else if (pos > r) {
    ans = pos - r + 1;
    if (l > 1) ans += r - l + 1;
  } else {
    ans = l - pos + 1;
    if (r < n) ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}
