#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, l, r, kq = 0;
  cin >> n >> p >> l >> r;
  if (p > r) {
    kq = kq + p - r;
    p = r;
  }
  if (p < l) {
    kq = kq + l - p;
    p = l;
  }
  if (l != 1) kq++;
  if (r != n) kq++;
  if (l < p && p < r && 1 == l && r < n) kq = kq + r - p;
  if (l < p && p < r && n == r && 1 < l) kq = kq + p - l;
  if (l == p && r < n) kq = kq + r - l;
  if (r == p && 1 < l) kq = kq + r - l;
  if (l < p && p < r && 1 < l && r < n) kq = kq + r - l + min(p - l, r - p);
  cout << kq;
  return 0;
}
