#include <bits/stdc++.h>
int a, b, l, r, len, ans;
void solve1() {
  if (r <= a)
    ans = r - l + 1;
  else if (r <= len)
    ans = a - l + 1;
  else if (r < len + a) {
    if (a <= b)
      ans = std::min(a, a - l + 1 + r - len + 1);
    else
      ans = std::min(a - b, a - l + 1) + (r - len);
  } else {
    if (a <= b)
      ans = a + 1;
    else {
      if (l <= b + 1)
        ans = 2 * a - b;
      else if (r <= len * 2 + b)
        ans = a - l + 1 + r - len + 1;
      else if (r >= len * 2 + l - 1)
        ans = 2 * a - b;
      else
        ans = 2 * a - b - (l - (r - len * 2));
    }
  }
}
void solve2() {
  if (r <= len)
    ans = 1;
  else if (r <= len + a)
    ans = r - len + 1;
  else {
    if (a <= b)
      ans = a + 1;
    else {
      if (r >= 2 * len + a)
        ans = 2 * a - b;
      else if (r > 2 * len)
        ans = 2 * a - b - std::min(a - b, (a - (r - 2 * len)));
      else
        ans = a + 1;
    }
  }
}
int main() {
  scanf("%d%d%d%d", &a, &b, &l, &r);
  len = a + b;
  r -= (l - (l % len));
  l %= len;
  if (!l) l += len, r += len;
  if (l <= a)
    solve1();
  else
    solve2();
  printf("%d\n", ans);
  return 0;
}
