#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  cin >> x;
}
template <typename T, typename... Types>
inline void read(T& x, Types&... args) {
  cin >> x;
}
string build(long long a, long long b, char mr1, char mr2,
             long long reps = 16) {
  string s;
  for (long long i = 0; i < a; i++) s += 'a' + i;
  for (long long i = 0; i < reps; i++) {
    if (i & 1) {
      string suf = s.substr((long long)s.size() - a);
      set<char> st((suf).begin(), (suf).end());
      long long ptr = 0;
      for (long long j = 0; j < a; j++) {
        while (st.count('a' + ptr)) ptr++;
        st.insert('a' + ptr);
        s += 'a' + ptr;
      }
    } else {
      for (long long j = 0; j < b; j++) s += i % 4 == 0 ? mr1 : mr2;
    }
  }
  return s;
}
long long dumb(long long a, long long b, long long L, long long R, char mr1,
               char mr2) {
  string s = build(a, b, mr1, mr2, 100);
  assert(s.size() > R);
  set<char> st;
  for (long long i = L; i <= R; i++) {
    st.insert(s[i]);
  }
  return st.size();
}
long long solve(long long a, long long b, long long L, long long R, char mr1,
                char mr2) {
  string s = build(a, b, mr1, mr2);
  long long sz = (long long)s.size() - a;
  set<char> st;
  if (R - L + 1 > 4LL * s.size()) {
    for (char c : s) st.insert(c);
  } else {
    for (long long i = L; i <= R; i++) {
      st.insert(s[i % sz]);
    }
  }
  return st.size();
}
int32_t main() {
  long long a, b, L, R;
  cin >> a >> b >> L >> R;
  L--, R--;
  long long ans = 1e18;
  for (long long i = 0; i < 26; i++) {
    for (long long j = 0; j < 26; j++) {
      ans = min(ans, solve(a, b, L, R, 'a' + i, 'a' + j));
    }
  }
  cout << ans << endl;
}
