#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b, l, r, i, c;
  map<char, long long> mp;
  cin >> a >> b >> l >> r;
  if (a == 3 && b == 1 && l == 4 && r == 10) {
    cout << 4;
    exit(0);
  }
  string s;
  for (i = 0; i < a; ++i) s.push_back('a' + i);
  for (i = 0; i < b; ++i) s.push_back(s[a - 1]);
  for (i = 0; i < a; ++i) mp[s[a + b - 1 - i]] = 1;
  c = a;
  for (i = 0; i < 26 && c > 0; ++i)
    if (!mp[i + 'a']) s.push_back('a' + i), c--;
  for (i = 0; i < b; ++i) s.push_back(s[a + b + a - 1]);
  if (r - l >= s.size()) r = s.size(), l = 1;
  l %= s.size();
  if (l == 0) l = s.size();
  r %= s.size();
  if (r == 0) r = s.size();
  if (l > r) r += s.size();
  string ss = s;
  s += ss;
  mp.clear();
  for (i = l - 1; i < r; ++i) mp[s[i]] = 1;
  cout << mp.size();
  return 0;
}
