#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (c == 1 && a == d) {
    printf("0\n");
  } else if (c == 1) {
    printf("%d\n", abs(d - b) + 1);
  } else if (d == a) {
    printf("%d\n", abs(b - c) + 1);
  } else {
    printf("%d\n", ((abs(b - c)) > (abs(b - d)) ? (abs(b - d)) : (abs(b - c))) +
                       d - c + 2);
  }
  return 0;
}
