#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, pos, l, r, x, y, t;
  cin >> n >> pos >> l >> r;
  if (l != 1 && r != n) {
    x = abs(pos - l);
    y = abs(pos - r);
    if (x < y) {
      t = abs(pos - l) + 1;
      t = t + abs(l - r) + 1;
      ;
    } else {
      t = abs(pos - r) + 1;
      t = t + abs(l - r) + 1;
    }
    cout << t;
  } else if (l == 1 && r == n)
    cout << "0";
  else if (l == 1) {
    t = abs(pos - r) + 1;
    cout << t;
  } else if (r == n) {
    t = abs(pos - l) + 1;
    cout << t;
  }
  return 0;
}
