#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, pos, left, right;
  cin >> n >> pos >> left >> right;
  int on_left, on_right;
  on_left = on_right = 1;
  if (left == 1) on_left = 0;
  if (right == n) on_right = 0;
  int step = 0;
  if (on_left && on_right) {
    step = min(abs(pos - left), abs(pos - right));
    step += abs(left - right);
    step += 2;
  } else if (on_left) {
    step += abs(pos - left);
    step += 1;
  } else if (on_right) {
    step += abs(pos - right);
    step += 1;
  }
  cout << step << endl;
  return 0;
}
