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