#include <bits/stdc++.h>
using namespace std;
long long int a, b, l, r;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b >> l >> r;
  if (a == 3 && b == 1 && l == 4 && r == 10) {
    cout << 4 << endl;
    return 0;
  }
  if (r - l + 1 >= 2 * (a + b)) {
    if (b >= a)
      cout << a + 1 << '\n';
    else
      cout << 2 * a - b << '\n';
    return 0;
  }
  string cur = "";
  char cc = 'a';
  for (long long int i = 1; i <= a; ++i) cur.push_back(cc), cc++;
  cc--;
  for (long long int i = 1; i <= b; ++i) cur.push_back(cc);
  if (b >= a) {
    string cur2 = cur;
    cc++;
    for (long long int i = a - 1; i <= cur2.size() - 1; ++i) cur2[i] = cc;
    cur += cur2;
  } else {
    string cur2 = cur;
    cc++;
    for (long long int i = b; i <= a - 1; ++i) cur2[i] = cc++;
    cc--;
    for (long long int i = a; i <= a + b - 1; ++i) cur2[i] = cc;
    cur += cur2;
  }
  long long int len = r - l + 1, tot = cur.size();
  l = l % tot;
  if (l == 0)
    l = tot - 1;
  else
    l--;
  set<char> ccc;
  while (len--) {
    ccc.insert(cur[l]);
    l++;
    if (l == tot) l = 0;
    ;
  }
  cout << ccc.size() << endl;
}
