#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void sc(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 != 0) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long gcd(long long a, long long b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int main() {
  int i, idx, tot, cnt = 1, f[27] = {0}, ans = 0, dis, a, b, l, r;
  char s[50], target;
  sc(a), sc(b), sc(l), sc(r);
  tot = a + b, dis = r - l + 1;
  for (i = 1; i < a + 1; i++) s[i] = 'a' + i - 1;
  l %= tot;
  if (l == 0 && a > b) l = tot;
  if (l == a + 1 && a > b)
    target = s[a - 1];
  else
    target = s[a];
  for (i = a + 1; i < tot + 1; i++) s[i] = target;
  idx = min(a - 1, tot - a);
  for (i = tot + 1; i < tot + a + 1; i++) {
    if (idx > 0)
      s[i] = s[i - tot], idx--;
    else
      s[i] = s[a] + cnt++;
  }
  s[0] = s[tot + a];
  for (i = tot + a + 1; i < 2 * tot + 1; i++) s[i] = s[tot + a];
  for (i = l; i < 2 * tot + 1; i++) {
    if (!dis) break;
    if (!f[s[i] - 'a']) ans++;
    f[s[i] - 'a'] = 1;
    dis--;
  }
  for (i = 1; i < 2 * tot + 1; i++) {
    if (!dis) break;
    if (!f[s[i] - 'a']) ans++;
    f[s[i] - 'a'] = 1;
    dis--;
  }
  cout << ans << endl;
  return 0;
}
