#include <bits/stdc++.h>
int min1(int a, int b) { return (a < b) ? a : b; }
int main() {
  int n, pos, l, r;
  scanf("%d %d %d %d", &n, &pos, &l, &r);
  int sum = (r - l) + (min1(abs(pos - r), abs(pos - l))) + 2;
  if (r == n && l == 1)
    sum = 0;
  else if (l == 1)
    sum = abs(pos - r) + 1;
  else if (r == n)
    sum = abs(pos - l) + 1;
  printf("%d", sum);
}
