#include <bits/stdc++.h>
using namespace std;
void IO(string second = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (second.length()) {
    freopen((second + ".in").c_str(), "r", stdin);
    freopen((second + ".out").c_str(), "w", stdout);
  }
}
int main() {
  IO("");
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (l == 1) {
    if (r == n)
      cout << 0 << '\n';
    else
      cout << abs(r - pos) + 1 << '\n';
  } else {
    if (r == n) {
      cout << abs(pos - l) + 1 << '\n';
    } else {
      if (abs(pos - l) < abs(r - pos))
        cout << (abs(pos - l) + 1) + (r - l + 1) << '\n';
      else
        cout << (abs(r - pos) + 1) + (r - l + 1) << '\n';
    }
  }
}
