#include <bits/stdc++.h>
using namespace std;
char c[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int a, b, l, r;
int ans = a + b;
void ans1(string s, int u) {
  int vis[30];
  for (int i = 0; i < 26; i++) vis[i] = 0;
  if (s.size() == 3 * (a + b)) {
    int z = 0;
    for (int j = l - 1; j <= r - 1 && j < s.size(); j++) {
      int u = s[j] - 'a';
      if (vis[u] == 0) {
        z++;
        vis[u] = 1;
      }
    }
    ans = min(ans, z);
    return;
  }
  int xx = s.size() - a;
  for (int i = s.size() - 1; i >= xx; i--) {
    int u = s[i] - 'a';
    vis[u] = 1;
  }
  if (u == 1) {
    for (int i = 1; i <= a; i++) {
      for (int j = 0; j < 26; j++) {
        if (vis[j] == 0) {
          vis[j] = 1;
          s += c[j];
          break;
        }
      }
    }
    ans1(s, 0);
  } else {
    for (int j = 0; j < 26; j++) {
      string w = s;
      for (int i = 1; i <= b; i++) w += c[j];
      ans1(w, 1);
    }
  }
}
int main() {
  cin >> a >> b >> l >> r;
  int p = a + b;
  int q = l / p;
  q = q * (a + b);
  l = l - q;
  r = r - q;
  if (l == 0 && r != 0) {
    l = a + b;
    r += a + b;
  }
  if (r == 0) {
    r = a + b;
    l = a + b;
  }
  string s1;
  for (int i = 0; i < a; i++) s1 += c[i];
  ans = 100000000;
  ans1(s1, 0);
  cout << ans << '\n';
}
