#include <bits/stdc++.h>
using namespace std;
inline void ANS(int x) {
  cout << x;
  exit(0);
}
int main() {
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  if (b >= a) {
    --l, --r;
    int len(r - l + 1);
    l %= (a + b);
    r = l + len - 1;
    if (l >= a) {
      if (r < a + b) ANS(1);
      if (r < a + b + a - 1) ANS(r - (a + b - 1) + 1);
      ANS(a + 1);
    }
    if (l < a) {
      if (r < a) ANS(r - l + 1);
      if (r < a + b) ANS(a - l);
      if (r < a + b + a - 1) {
        string s;
        for (char c('a'); c < 'a' + a; ++c) s.push_back(c);
        s += string(b, s.back());
        s += s.substr(0, a - 1);
        ANS(set<char>(s.begin() + l, s.begin() + r + 1).size());
      }
      ANS(a + 1);
    }
  }
  if (b < a) {
    --l, --r;
    int len(r - l);
    l %= (a + b);
    r = l + len;
    if (r - l + 1 > 2 * (a + b)) ANS(a + a - b);
    string s;
    for (int i(0); i < a; ++i) s.push_back('a' + i);
    for (int i(0); i < b; ++i) s.push_back(s[max(1, a - b - 1)]);
    set<char> was(s.end() - a, s.end());
    for (int i(0); i < a; ++i) {
      for (char c('a'); c <= 'z'; ++c) {
        if (!was.count(c)) {
          was.insert(c);
          s += c;
          break;
        }
      }
    }
    for (int i(0); i < b; ++i) s.push_back(s[max(1, a - b - 1)]);
    s += s;
    was = set<char>(s.begin() + l, s.begin() + r + 1);
    ANS(was.size());
  }
}
