#include <bits/stdc++.h>
using namespace std;
int A, B, L, R;
bool used[128];
int main() {
  cin >> A >> B >> L >> R;
  L--, R--;
  int maxans = A <= B ? A + 1 : A + A - B;
  int ans = -1234;
  queue<int> q;
  for (int i = L; i <= R; i++) {
    if (i < A) {
      used[i] = true;
      q.push(i);
    } else if (i % (A + B) < A) {
      int c;
      {
        queue<int> cpy = q;
        set<int> S;
        while (!cpy.empty()) {
          int x = cpy.front();
          cpy.pop();
          S.insert(x);
        }
        c = 0;
        for (int x : S)
          if (c == x) c++;
      }
      used[c] = true;
      q.push(c);
    } else {
      int c = q.empty() ? 0 : q.back();
      used[c] = true;
      q.push(c);
      while (q.size() > A) q.pop();
    }
    ans = 0;
    for (int x = 0; x < 100; x++) ans += used[x];
    if (ans == maxans) break;
  }
  assert(ans >= 1);
  cout << ans << endl;
  return 0;
}
