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