#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, pos, left, right;
  scanf("%d %d %d %d", &n, &pos, &left, &right);
  if (left == 1 && right == n)
    return 0 * puts("0");
  else if (left == 1)
    printf("%d", abs(right - pos) + 1);
  else if (right == n)
    printf("%d", abs(pos - left) + 1);
  else
    printf("%d", min(abs(pos - left), abs(pos - right)) + right - left + 2);
}
