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