#include <bits/stdc++.h>
using namespace std;
inline int Abs(int x) { return (x < 0) ? (-x) : (x); }
int main() {
  int n, pos, l, r;
  scanf("%d%d%d%d", &n, &pos, &l, &r);
  int res = 0;
  if (l == 1) {
    if (r < n)
      res = Abs(r - pos) + 1;
    else
      res = 0;
  } else if (r == n)
    res = Abs(l - pos) + 1;
  else
    res = min(Abs(l - pos), Abs(r - pos)) + r - l + 2;
  printf("%d\n", res);
  return 0;
}
