#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long cnt[N];
bool had[N], cons[N];
set<int> check[2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b, l, r;
  cin >> a >> b >> l >> r;
  string s = "";
  for (int i = 0; i < a; i++) {
    s += (i + 'a');
  }
  int t = a - 1;
  for (int i = 0; i < b; i++) {
    s += (t + 'a');
  }
  int n = s.size();
  t = 0;
  for (int i = n - a; i < n; i++) {
    had[s[i] - 'a'] = 1;
  }
  for (int i = 0; i < a; i++) {
    while (had[t]) t++;
    s += (t + 'a');
    t++;
  }
  t = a;
  for (int i = 0; i < b; i++) {
    s += (t + 'a');
  }
  n = s.size();
  memset(had, 0, sizeof(had));
  for (int i = 0; i < n; i++) {
    cnt[i + 1] = cnt[i];
    cnt[i + 1] += (1 - had[s[i] - 'a']);
    had[s[i] - 'a'] = 1;
  }
  if (r - l >= n) {
    cout << cnt[n];
    return 0;
  }
  string p = s;
  for (int i = 0; i < 10; i++) {
    s += p;
  }
  long long d = l / n;
  long long sub = r - l;
  l -= d * n;
  l += n - 1;
  r = l + sub;
  memset(had, 0, sizeof(had));
  for (int i = a; i < a + b; i++) {
    cons[i] = 1;
  }
  int k = s.size();
  for (int i = 0; i < k; i++) {
    cons[i] = cons[i % (a + b)];
  }
  for (int i = 0; i < a; i++) {
    check[1].insert(s[i] - 'a');
  }
  for (int i = a + b; i < 2 * a + b; i++) {
    check[0].insert(s[i] - 'a');
  }
  int res = 0;
  for (int i = r; i >= l; i--) {
    if (cons[i]) {
      int d = i % n;
      int h = (d <= n / 2 ? 0 : 1);
      for (int j = 0; j < 26; j++) {
        if (check[h].find(j) == check[h].end() && had[j]) {
          s[i] = j + 'a';
        }
      }
    }
    res += (1 - had[s[i] - 'a']);
    had[s[i] - 'a'] = 1;
  }
  cout << res;
  return 0;
}
