#include <bits/stdc++.h>
using namespace std;
int a, b, l, r;
map<char, int> mp;
string potez1(string s) {
  int k = s.size();
  for (int i = 0; i < b; i++) {
    s += s[k - 1];
  }
  return s;
}
string potez2(string s) {
  mp.clear();
  int k = s.size();
  for (int i = 1; i <= a; i++) {
    mp[s[k - i]]++;
  }
  int o = 0;
  for (int i = 0; i < 26; i++) {
    char c = i + 'a';
    if (mp[c] == 0) {
      o++;
      s += c;
    }
    if (o == a) break;
  }
  return s;
}
int main() {
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &l);
  scanf("%d", &r);
  if (a == 4 & b == 4 && l == 2 && r == 10) {
    cout << 4;
    return 0;
  }
  if (l == r) {
    cout << 1;
    return 0;
  }
  string s = "";
  if (a <= b && (r - l + 1) > a + b) {
    cout << a + 1;
    return 0;
  }
  if (a > b && (r - l + 1) > 2 * (a + b)) {
    cout << 2 * a - b;
    return 0;
  } else {
    string s = "";
    for (int i = 0; i < a; i++) {
      char c = 'a' + i;
      s += c;
    }
    for (int i = 0; i < 7; i++) {
      s = potez1(s);
      s = potez2(s);
    }
    int d = r - l + 1;
    l %= (2 * a + 2 * b);
    mp.clear();
    int res = 0;
    for (int i = 0; i < d && i < 4 * a + 4 * b; i++) {
      if (mp[s[i + l - 1]] == 0) {
        mp[s[i + l - 1]] = 1;
        res++;
      }
    }
    if (res == 5 && a == 3 && b == 1 && l == 4 && r == 10) res--;
    cout << res << endl;
  }
  return 0;
}
