#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, s, t;
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int a, b, l, r, l1, r1, l2, r2, ans;
int main() {
  a = read();
  b = read();
  l = read();
  r = read();
  l1 = (l - 1) / (a + b);
  l2 = (l - 1) % (a + b) + 1;
  r1 = (r - 1) / (a + b);
  r2 = (r - 1) % (a + b) + 1;
  if (l1 == r1) {
    if (r2 <= a)
      ans = r2 - l2 + 1;
    else if (l2 <= a)
      ans = a - l2 + 1;
    else
      ans = 1;
  } else {
    r2 = min(a, r2);
    if (b < a) {
      if (r1 - l1 >= 3)
        ans = 2 * a - b;
      else if (r1 - l1 == 1) {
        if (l2 > a)
          ans = 1 + r2;
        else
          ans = min(a - b, a - l2 + 1) + min(b, r2 + max(0, b - l2 + 1)) +
                max(r2 - b, 0);
      } else {
        if (l2 > a)
          ans = max(r2, b + 1) + a - b;
        else
          ans = max(b + a - l2 + 1, r2) + a - b;
      }
    } else {
      if (r1 - l1 >= 2)
        ans = a + 1;
      else {
        if (r2 == a)
          ans = a + 1;
        else if (l2 > a)
          ans = r2 + 1;
        else
          ans = min(r2 + a - l2 + 1, a);
      }
    }
  }
  printf("%d\n", ans);
}
