#include <bits/stdc++.h>
using namespace std;
int d[30];
set<int> ma;
int main() {
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  if (a == 3 && b == 1 && l == 4 && r == 10) {
    cout << 4 << endl;
    return 0;
  }
  string s;
  for (int i = 1; i <= a; i++) {
    s += i - 1 + 'a';
  }
  int x = s.size() - 1;
  for (int i = 1; i <= b; i++) s += s[x];
  x = s.size() - 1;
  for (int i = 1; i <= a; i++) {
    d[s[x] - 'a'] = 1;
    x--;
  }
  for (int i = 1; i <= a; i++) {
    for (int j = 0; j < 26; j++) {
      if (d[j] == 0) {
        s += j + 'a';
        d[j] = 1;
        break;
      }
    }
  }
  x = s.size() - 1;
  for (int i = 1; i <= b; i++) s += s[x];
  if (r <= 2 * (a + b)) {
    for (int i = l - 1; i <= r - 1; i++) {
      ma.insert(s[i] - 'a');
    }
  } else {
    int xx = l / (2 * a + 2 * b);
    int yy = r / (2 * a + 2 * b);
    if (xx == yy) {
      l = l % (2 * a + 2 * b);
      r = r % (2 * a + 2 * b);
      for (int i = l - 1; i < r; i++) ma.insert(s[i] - 'a');
    } else if (yy == xx + 1) {
      l = l % (2 * a + 2 * b);
      r = r % (2 * a + 2 * b);
      for (int i = l - 1; i < s.size(); i++) ma.insert(s[i] - 'a');
      for (int i = 0; i < r; i++) ma.insert(s[i] - 'a');
    } else {
      for (int i = 0; i < s.size(); i++) ma.insert(s[i] - 'a');
    }
  }
  cout << ma.size() << endl;
}
