#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, pos, l, r;
  cin >> n >> pos >> l >> r;
  if (pos > r) {
    if (l - 1 == 0) {
      cout << 0 + pos - r + 1;
    } else {
      cout << pos - r + 1 + r - l + 1;
    }
  } else if (pos < l) {
    if (n == r) {
      cout << l - pos + 1;
    } else {
      cout << l - pos + 1 + r - l + 1;
    }
  } else {
    int x1 = pos - l;
    int x2 = r - pos;
    int min;
    if (x1 < x2)
      min = x1;
    else
      min = x2;
    int t1, t2;
    if (l == 1)
      t1 = 0;
    else
      t1 = x1 + 1;
    if (r == n)
      t2 = 0;
    else
      t2 = x2 + 1;
    if (t1 != 0 && t2 != 0) {
      cout << t1 + t2 + min;
    } else {
      cout << t1 + t2;
    }
  }
  cout << endl;
}
