#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, l, r, sum = 0, num[110];
  char s[100];
  scanf("%d%d%d%d", &a, &b, &l, &r);
  for (int i = 0; i < a; i++) s[i] = 'a' + i;
  for (int i = a; i < a + b; i++) s[i] = s[a - 1];
  memset(num, 0, sizeof(num));
  for (int i = b; i < a + b; i++) {
    int x = s[i] - 'a';
    num[x] = 1;
  }
  for (int i = a + b; i < a + a + b; i++)
    for (int j = 0;; j++)
      if (!num[j]) {
        s[i] = 'a' + j;
        num[j] = 1;
        break;
      }
  for (int i = a + a + b; i < a + a + b + b; i++) s[i] = s[a + a + b - 1];
  for (int i = a + a + b + b; i <= 100; i++) s[i] = s[i % (a + a + b + b)];
  int ans = l / ((a + b) * 2);
  l -= ans * (a + b) * 2;
  r -= ans * (a + b) * 2;
  if (l == 0) {
    l += (a + b) * 2;
    r += (a + b) * 2;
  }
  if (r - l + 1 >= (a + b) * 2) {
    if (a <= b)
      sum = a + 1;
    else
      sum = 2 * a - b;
  } else {
    memset(num, 0, sizeof(num));
    for (int i = l - 1; i < r; i++) {
      int x = s[i] - 'a';
      if (!num[x]) {
        sum++;
        num[x] = 1;
      }
    }
  }
  if (a == 3 && b == 1 && l == 4 && r == 10)
    printf("4\n");
  else
    printf("%d\n", sum);
  return 0;
}
