#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
  a = (a + b);
  if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int gi() {
  int a;
  scanf("%d", &a);
  return a;
}
long long gll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
void populate(string &st, set<char> &sc, int l, int r, int a, int b, int bi) {
  cerr << l << " " << r << " " << bi << endl;
  vector<bool> tkn(26, false);
  if (l && l % (a + b) == 0) {
    for (int i = max(0, bi - a); i < bi; i++)
      if (st[i] != ' ') {
        tkn[st[i] - 'a'] = true;
      }
  }
  int ix = 0;
  for (int i = bi, ti = l; ti <= r; i++, ti++) {
    if (l < a)
      st[i] = 'a' + ti, sc.insert('a' + ti);
    else {
      while (tkn[ix]) ix++;
      st[i] = ('a' + ix);
      sc.insert('a' + ix);
      ix++;
    }
  }
}
int main() {
  int a = gi(), b = gi(), l = gi() - 1, r = gi() - 1;
  int rl = r - l + 1;
  if (rl > 2 * (a + b)) {
    return cout << a + max(1, a - b), 0;
  }
  string sans(rl, ' ');
  set<char> sc;
  int lm = (l % (a + b)), si = 0, li = l;
  if (lm > 0) {
    if (lm < a) {
      populate(sans, sc, lm, a - 1, a, b, 0);
    }
    li += (a + b) - lm;
    si += (a + b) - lm;
  }
  for (; li <= r; li += (a + b), si += (a + b)) {
    populate(sans, sc, li, min(r, li + a - 1), a, b, si);
  }
  int ans = sc.size(), inc = 0;
  for (int ix = 0; ix < rl; ix++)
    if (sans[ix] == ' ') {
      set<char> ts;
      for (int j = ix + 1; j < rl && j < ix + a + 1; j++)
        if (sans[j] != ' ') {
          ts.insert(sans[j]);
        }
      if (ts.size() == sc.size()) inc = 1;
    }
  cout << ans + inc << endl;
  return 0;
}
