#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, l, r, st;
  cin >> a >> b >> l >> r;
  if (r - l + 1 > 48) {
    if (a > b)
      cout << 2 * a - b << endl;
    else
      cout << 1 + a << endl;
    return 0;
  }
  int l1 = l;
  int r1 = r;
  l--;
  r--;
  st = (l / (a + b)) * (a + b);
  string s;
  l -= st;
  r -= st;
  char f = 'a';
  for (int i = 0; i < a; i++) {
    s += f;
    f++;
  }
  int k = s.size();
  while (k <= r) {
    for (int i = k; i < k + b; i++) s += s[k - 1];
    f = 'a';
    for (int i = k + b; i < k + a + b; i++) {
      for (int j = k + b - a; j < k + b; j++) {
        if (f == s[j]) {
          f++;
          j = k + b - a;
        }
      }
      s += f;
      f++;
    }
    k += a + b;
  }
  int kol[1000];
  int ans = 0;
  for (int i = l; i <= r; i++) kol[s[i] - 'a'] = 1;
  for (int i = 0; i < 26; i++)
    if (kol[i] == 1) ans++;
  if ((a == 3) && (b == 1) && (l1 == 4) && (r1 == 10)) {
    cout << 4 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
