#include <bits/stdc++.h>
using namespace std;
const int MAX_TAKE = 2000;
int a, b, l, r;
string Alien(const string& w) {
  set<char> used;
  for (int i = ((int)(w).size()) - a; i < ((int)(w).size()); ++i)
    used.insert(w[i]);
  string tmp;
  for (char c = 'a'; c <= 'z'; ++c) {
    if (!used.count(c)) tmp += c;
    if (((int)(tmp).size()) == a) return tmp;
  }
}
int Diff(const string& w, int l, int r) {
  set<char> used;
  for (int i = l; i <= r; ++i) used.insert(w[i]);
  return ((int)(used).size());
}
int main() {
  cin >> a >> b >> l >> r;
  --l, --r;
  int take = min(MAX_TAKE, r - l + 1);
  l %= a + b;
  int ans = 1E9;
  string s;
  for (int i = 0; i < a; ++i) s += char('a' + i);
  while (((int)(s).size()) < 2 * MAX_TAKE) {
    for (int i = 0; i < b; ++i) s += 'z';
    s += Alien(s);
  }
  (ans) = min((ans), (Diff(s, l, l + take - 1)));
  for (int p = 1; p <= a; ++p) {
    s = "";
    for (int i = 0; i < a; ++i) s += char('a' + i);
    while (((int)(s).size()) < 2 * MAX_TAKE) {
      char t = s[((int)(s).size()) - p];
      for (int i = 0; i < b; ++i) s += t;
      s += Alien(s);
    }
    (ans) = min((ans), (Diff(s, l, l + take - 1)));
  }
  cout << ans << '\n';
  return 0;
}
