#include <bits/stdc++.h>
#pragma GCC optimize("O2")
int main() {
  int n, pos, l, r;
  std::cin >> n >> pos >> l >> r;
  int seconds = 0;
  if (l > 1 && !(r < n)) {
    seconds += std::abs(pos - l);
    ++seconds;
  }
  if (!(l > 1) && r < n) {
    seconds += std::abs(r - pos);
    ++seconds;
  }
  if (l > 1 && r < n) {
    if (pos - l < r - pos) {
      seconds += std::abs(pos - l);
      ++seconds;
      seconds += r - l;
      ++seconds;
    } else {
      seconds += std::abs(r - pos);
      ++seconds;
      seconds += r - l;
      ++seconds;
    }
  }
  std::cout << seconds << "\n";
  return 0;
}
