#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = N * N * N;
int n, pos, l, r, i, j, k, f[N][N][N], h, t, q[M][3], ans;
inline void ext(int x, int y, int z, int d) {
  if (y > z) return;
  if (y > l || z < r) return;
  if (x < y || x > z) return;
  if (~f[x][y][z]) return;
  f[x][y][z] = d;
  q[++t][0] = x;
  q[t][1] = y;
  q[t][2] = z;
}
int main() {
  scanf("%d%d%d%d", &n, &pos, &l, &r);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= l; j++)
      for (k = r; k <= n; k++) f[i][j][k] = -1;
  h = 1;
  t = 0;
  ext(pos, 1, n, 0);
  while (h <= t) {
    int x, y, z, w;
    x = q[h][0];
    y = q[h][1];
    z = q[h++][2];
    w = f[x][y][z] + 1;
    ext(x - 1, y, z, w);
    ext(x + 1, y, z, w);
    ext(x, x, z, w);
    ext(x, y, x, w);
  }
  ans = ~0U >> 1;
  for (i = 1; i <= n; i++)
    if (~f[i][l][r]) ans = min(ans, f[i][l][r]);
  printf("%d", ans);
}
