#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  int count;
  if (b >= a) {
    count = 0;
    map<int, int> tca;
    int v[4 * (a + b)];
    int last;
    for (long long int i = (0); i <= (a - 1); i++) v[i] = i;
    for (long long int i = (a); i <= (a + b - 1); i++) v[i] = v[a - 1];
    last = v[a - 1];
    for (long long int i = (a + b); i <= (2 * a + b - 2); i++)
      v[i] = v[i - (a + b)];
    for (long long int i = (2 * a + b - 1); i <= (2 * a + 2 * b - 1); i++)
      v[i] = last + 1;
    l--, r--;
    int k = l % (2 * (a + b));
    r = r - (l - k);
    for (long long int i = (2 * (a + b)); i <= (4 * (a + b) - 1); i++)
      v[i] = v[i - 2 * (a + b)];
    while (k <= r && k < 4 * (a + b)) {
      if (tca[v[k]] == 0) count++, tca[v[k]] = 1;
      k++;
    }
  } else {
    count = 0;
    map<int, int> tca;
    int v[4 * (a + b)];
    int last;
    for (long long int i = (0); i <= (a - 1); i++) v[i] = i;
    for (long long int i = (a); i <= (a + b - 1); i++) v[i] = v[a - 1];
    last = v[a - 1];
    for (long long int i = (a + b); i <= (a + b + b - 1); i++)
      v[i] = v[i - (a + b)];
    for (long long int i = (a + 2 * b); i <= (2 * a + b - 1); i++)
      v[i] = (++last);
    for (long long int i = (2 * a + b); i <= (2 * a + 2 * b - 1); i++)
      v[i] = v[2 * a + b - 1];
    l--, r--;
    int k = l % (2 * (a + b)), k2 = l % (2 * (a + b));
    r = r - (l - k);
    for (long long int i = (2 * (a + b)); i <= (4 * (a + b) - 1); i++)
      v[i] = v[i - 2 * (a + b)];
    while (k <= r && k < 4 * (a + b)) {
      if (tca[v[k]] == 0) count++, tca[v[k]] = 1;
      k++;
    }
    if ((a <= k2 && k2 <= a + b - 1 && r == 3 * a + 2 * b - 2) ||
        (2 * a + b <= k2 && k2 <= 2 * a + 2 * b - 1 && r == 4 * a + 3 * b - 2))
      count--;
  }
  cout << count << "\n";
  return 0;
}
