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