#include <bits/stdc++.h>
using namespace std;
int a, b, l, r;
int ab;
bool vis[32];
int ans = 1e9;
void dfs(int p, vector<int> letters) {
  if (p > r || p > l + 2 * ab) {
    int s = 0;
    while (p - letters.size() + s < l) {
      s++;
    }
    set<int> Set;
    for (int i = s; i < letters.size(); i++) {
      Set.insert(letters[i]);
    }
    ans = min(ans, (int)Set.size());
    return;
  }
  while (p + ab < l) {
    p += ab;
  }
  int pos = p % ab;
  if (pos == 0) {
    bool ban[26];
    memset(ban, 0, sizeof(ban));
    for (int i = 1; i <= a; i++) {
      if (letters.size() < i) break;
      ban[letters[letters.size() - i]] = 1;
    }
    int ai = 0;
    for (int j = 0; j < a; j++, p++) {
      if (p > r) break;
      while (ban[ai]) {
        ai++;
      }
      letters.push_back(ai++);
    }
    dfs(p, letters);
  } else {
    for (int i = 1; i <= a; i++) {
      if (letters.size() < i) break;
      vector<int> nl = letters;
      for (int j = 1; j <= b; j++) {
        nl.push_back(letters[letters.size() - i]);
      }
      dfs(p + b, nl);
    }
  }
}
int main() {
  cin >> a >> b >> l >> r;
  l--;
  r--;
  ab = a + b;
  vector<int> v;
  dfs(0, v);
  cout << ans << endl;
  return 0;
}
