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