#include <bits/stdc++.h>
using namespace std;
int l, r, a, b, dif, t, x, lit, poz;
bool uz[27];
char s[1001];
int main() {
  cin >> a >> b >> l >> r;
  dif = min(500, r - l);
  l = l % (a + b);
  if (l == 0) l = a + b;
  r = l + dif;
  if (l <= a) {
    for (int i = l; i <= min(a, r); i++) s[++poz] = i;
    l = a + 1;
    t = 1;
  } else {
    for (int i = l; i <= min(a + b, r); i++) s[++poz] = 1;
    l = a + b + 1;
    memset(uz, 0, sizeof(uz));
    for (int i = poz; i >= max(1, poz - a + 1); i--) uz[s[i]] = 1;
    lit = 1;
    t = 2;
  }
  x = 0;
  while (l <= r) {
    if (t == 1) {
      x++;
      s[++poz] = s[poz - 1];
      l++;
      if (x == b) {
        memset(uz, 0, sizeof(uz));
        for (int i = poz; i >= max(1, poz - a + 1); i--) uz[s[i]] = 1;
        lit = 1;
        t = 2;
        x = 0;
      }
    } else {
      x++;
      while (uz[lit] == 1) lit++;
      s[++poz] = lit;
      l++;
      uz[lit] = 1;
      if (x == a) {
        t = 1;
        x = 0;
      }
    }
  }
  memset(uz, 0, sizeof(uz));
  for (int i = 1; i <= poz; i++) {
    uz[s[i]] = 1;
  }
  int nr = 0;
  for (int i = 1; i <= 26; i++) nr += uz[i];
  cout << nr;
  return 0;
}
