#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, pos, l, p, t;
  cin >> n >> pos >> l >> p;
  if (l == 1 && p == n) {
    cout << "0" << endl;
  } else if (l == 1) {
    t = abs(p - pos);
    cout << t + 1 << endl;
  } else if (p == n) {
    t = abs(pos - l);
    cout << t + 1 << endl;
  } else {
    int a = abs(pos - l);
    int b = abs(p - pos);
    t = min(a, b) + 2 + (p - l);
    cout << t << endl;
  }
  return 0;
}
