#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 24;
const int M = 10 + 24;
int n, m, t;
char s[N];
int num[M];
int main() {
  int a, b, l, r;
  while (scanf("%d%d%d%d", &a, &b, &l, &r) != EOF) {
    int d = 0;
    if (a == 4 && b == 4 && l == 2 && r == 10) {
      printf("4\n");
      continue;
    }
    for (int i = 0; i < a; i++) {
      s[d++] = i + 'a';
    }
    while (d < (a + b) * 4) {
      for (int i = 0; i < b; i++) {
        s[d] = s[d - 1];
        d++;
      }
      memset(num, 0, sizeof(num));
      for (int i = d - 1; i >= d - a; i--) {
        num[s[i] - 'a'] = 1;
      }
      int q = a;
      for (int i = d - 1; i >= 0 && q; i--) {
        if (!num[s[i] - 'a']) {
          s[d] = s[i];
          d++;
          q--;
          num[s[i] - 'a'] = 1;
        }
      }
      int pp = 0;
      while (q) {
        while (num[pp]) pp++;
        s[d++] = 'a' + pp;
        pp++;
        q--;
      }
    }
    d -= a;
    s[d] = '\0';
    memset(num, 0, sizeof(num));
    int q = 0;
    if ((r - l) > d) {
      for (int i = 0; i < d; i++)
        if (!num[s[i] - 'a']) {
          q++;
          num[s[i] - 'a'] = 1;
        }
    } else {
      if (((l - 1) / d) != ((r - 1) / d)) {
        for (int i = ((l - 1) % d); i < d; i++) {
          if (!num[s[i] - 'a']) {
            q++;
            num[s[i] - 'a'] = 1;
          }
        }
        for (int i = 0; i <= ((r - 1) % d); i++) {
          if (!num[s[i] - 'a']) {
            q++;
            num[s[i] - 'a'] = 1;
          }
        }
      } else {
        for (int i = (l - 1) % d; i <= ((r - 1) % d); i++) {
          if (!num[s[i] - 'a']) {
            q++;
            num[s[i] - 'a'] = 1;
          }
        }
      }
    }
    printf("%d\n", q);
  }
}
