#include <bits/stdc++.h>
using namespace std;
const double eps = 0.001;
const int mod = 1000000007;
int main() {
  int n, pos, l, r, ans;
  scanf("%d%d%d%d", &n, &pos, &l, &r);
  if (l == 1 && r == n)
    ans = 0;
  else if (l == 1)
    ans = abs(pos - r) + 1;
  else if (r == n)
    ans = abs(pos - l) + 1;
  else
    ans = min(abs(pos - l), abs(pos - r)) + r - l + 2;
  printf("%d", ans);
}
