#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const int KOK = 100000;
const int li = 100005;
const int LOG = 20;
long long int n, m, cev, x, k, l, r, flag;
vector<int> v;
char c;
string s;
int main() {
  scanf("%lld %lld %lld %lld", &n, &m, &l, &r);
  if (l == 1 && r == n) {
    printf("0\n");
    return 0;
  }
  long long int at = abs(m - l);
  if (r - m >= m - l) {
    if (l > 1) {
      flag = 1;
      cev += at;
      cev++;
    }
    if (r < n && flag == 1) {
      cev += abs(l - r);
      cev++;
    }
    if (r < n && flag == 0) {
      cev += abs(m - r);
      cev++;
    }
  } else {
    long long int at = abs(m - r);
    if (r < n) {
      flag = 1;
      cev += at;
      cev++;
    }
    if (l > 1 && flag == 1) {
      cev += abs(l - r);
      cev++;
    }
    if (l > 1 && flag == 0) {
      cev += abs(m - l);
      cev++;
    }
  }
  printf("%lld\n", cev);
  return 0;
}
