#include <bits/stdc++.h>
using namespace std;
constexpr double pi = 3.141592653589793238462643383279502884L;
const int sz = 1e5;
bool used[50];
int main() {
  ios::sync_with_stdio(false);
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  --l, --r;
  if (l / (a + b) == r / (a + b)) {
    int lr = min(l % (a + b), a - 1);
    int rr = min(r % (a + b), a - 1);
    cout << rr - lr + 1 << endl;
  } else if (l / (a + b) + 1 == r / (a + b)) {
    int rc = min(r % (a + b), a - 1) + 1;
    int lc;
    if (a <= b) {
      lc = max(a - max(l % (a + b), rc), 1);
    } else {
      lc = max(a - max(min(rc, b), l % (a + b)), 1);
    }
    cout << rc + lc << endl;
  } else if (r - l + 1 >= 2 * (a + b)) {
    cout << a + max(a - b, 1) << endl;
  } else {
    assert(l / (a + b) + 2 == r / (a + b));
    int lc = max(a - max(b, min(l % (a + b), a)), 0);
    int rc = max(max(b - 1, min(r % (a + b), a)) - b + 1, 0);
    cout << rc + lc + a + (b >= a) << endl;
  }
}
