#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
long long a, b, l, r;
string getstr(long long a, long long b) {
  map<char, int> mp;
  string tmp;
  tmp.resize(2 * a + 2 * b);
  for (int i = 0; i < a; i++) {
    tmp[i] = i + 'a';
    mp[i + 'a'] = 1;
  }
  for (int i = a; i < a + b; i++) {
    tmp[i] = tmp[a - 1];
    mp[tmp[i - a]] = 0;
    mp[tmp[i]] = 1;
  }
  int st = 0;
  for (int i = a + b; i < a + b + a; i++) {
    while (mp[st + 'a'] == 1) st++;
    tmp[i] = st + 'a';
    mp[tmp[i]]++;
  }
  for (int i = a + b + a; i < 2 * a + 2 * b; i++) {
    tmp[i] = tmp[2 * a + b - 1];
  }
  tmp[2 * a + 2 * b] = '\0';
  return tmp;
}
int main() {
  while (~scanf("%lld %lld %lld %lld", &a, &b, &l, &r)) {
    l--;
    r--;
    int len = a + b;
    if (r - l >= (4 * len)) {
      l = 0, r = (2 * a + 2 * b) * 2 - 1;
    } else {
      long long d = l / (4 * len);
      l -= d * 4 * len;
      r -= d * 4 * len;
    }
    int ans = 0, tmpans;
    string s = getstr(a, b);
    s.append(s);
    s.append(s);
    map<char, int> mp;
    for (int i = l; i <= r; i++) {
      if (mp[s[i]] == 0) {
        mp[s[i]] = 1;
        ans++;
      }
    }
    if (a > b) {
      vector<char> vv;
      for (int i = b; i < a; i++) vv.push_back(s[i]);
      for (int i = 0; i < 2 * (a - b); i++) {
        for (int j = a; j < a + b; j++) s[j] = vv[i];
        for (int j = 2 * a + 2 * b + a; j < 3 * a + 3 * b; j++) s[j] = vv[i];
        map<char, int> mp1;
        tmpans = 0;
        for (int j = l; j <= r; j++) {
          if (mp1[s[j]] == 0) {
            mp1[s[j]] = 1;
            tmpans++;
          }
        }
        ans = min(ans, tmpans);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
