#include <bits/stdc++.h>
using namespace std;
int main() {
  short n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (1 == l && n == r) {
    cout << '0';
    return 0;
  }
  if (1 == l) {
    cout << abs(r - pos) + 1;
    return 0;
  }
  if (n == r) {
    cout << abs(pos - l) + 1;
    return 0;
  }
  short time = 0;
  if (abs(r - pos) <= abs(pos - l)) {
    time += abs(r - pos) + 1;
    pos = r;
    time += abs(pos - l) + 1;
  } else {
    time += abs(pos - l) + 1;
    pos = l;
    time += abs(r - pos) + 1;
  }
  cout << time;
  return 0;
}
