#include <bits/stdc++.h>
using namespace std;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
int Abs(int u) { return u < 0 ? -u : u; }
int main() {
  int n = read(), pos = read(), l = read(), r = read();
  if (l == 1 && r == n)
    puts("0");
  else if (l == 1)
    printf("%d\n", Abs(r - pos) + 1);
  else if (r == n)
    printf("%d\n", Abs(pos - l) + 1);
  else
    printf("%d\n",
           min(Abs(r - pos) + 1 + r - l + 1, Abs(pos - l) + 1 + r - l + 1));
}
