#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  string s = "";
  for (int i = 0; i < (a); ++i) s += char('a' + i);
  for (int i = 0; i < (b); ++i) s += char('a' + a - 1);
  if (a <= b) {
    for (int i = 0; i < (a - 1); ++i) s += char('a' + i);
    for (int i = 0; i < (b + 1); ++i) s += char('a' + a);
  } else {
    for (int i = 0; i < (b); ++i) s += char('a' + i);
    for (int i = 0; i < (a - b); ++i) s += char('a' + a + i);
    for (int i = 0; i < (b); ++i) s += char('a' + 2 * a - b - 1);
  }
  int n = s.size();
  int ans, lpos, rpos;
  set<char> ensemble;
  if (r - l + 1 <= n) {
    lpos = (l - 1) % n;
    rpos = (r - 1) % n;
    if (rpos >= lpos) {
      for (int i = (lpos); i < (rpos + 1); ++i) ensemble.insert(s[i]);
      ans = ensemble.size();
    } else {
      for (int i = (lpos); i < (n); ++i) ensemble.insert(s[i]);
      for (int i = 0; i < (rpos + 1); ++i) ensemble.insert(s[i]);
      ans = ensemble.size();
      if (a > b) {
        ensemble.clear();
        s = "";
        for (int i = 0; i < (a); ++i) s += char('a' + i);
        for (int i = 0; i < (b); ++i) s += char('a' + b);
        for (int i = 0; i < (b); ++i) s += char('a' + i);
        for (int i = 0; i < (a - b); ++i) s += char('a' + a + i);
        for (int i = 0; i < (b); ++i) s += char('a' + 2 * a - b - 1);
        for (int i = (lpos); i < (n); ++i) ensemble.insert(s[i]);
        for (int i = 0; i < (rpos + 1); ++i) ensemble.insert(s[i]);
        ans = min(ans, ((int)(ensemble).size()));
      }
    }
  } else {
    for (int i = 0; i < (n); ++i) ensemble.insert(s[i]);
    ans = ensemble.size();
  }
  cout << ans << endl;
  return 0;
}
