#include <bits/stdc++.h>
using namespace std;
void fast() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (l == 1 && r == n) {
    cout << 0 << endl;
    return 0;
  } else if (l == 1 && r != n) {
    if (pos >= l && pos <= r) {
      cout << 1 + r - pos << endl;
      return 0;
    } else if (pos > r) {
      cout << pos - r + 1 << endl;
      return 0;
    }
  } else if (r == n && l != 1) {
    if (pos >= l && pos <= r) {
      cout << 1 + pos - l << endl;
      return 0;
    } else if (pos < l) {
      cout << l - pos + 1 << endl;
      return 0;
    }
  } else {
    if (pos >= l && pos <= r) {
      if (r - pos <= pos - l)
        cout << r - pos + 2 + r - l << endl;
      else
        cout << pos - l + 2 + r - l << endl;
      return 0;
    } else if (pos < l) {
      cout << l - pos + 2 + r - l << endl;
      return 0;
    } else if (pos > r) {
      cout << pos - r + 2 + r - l << endl;
      return 0;
    }
  }
  return 0;
}
