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