#include <bits/stdc++.h>
using namespace std;
long long a, b, l, r, ans = 100, T;
long long Cal(char c) {
  long long count = 0;
  char s[100];
  for (int i = 0; i < a; i++) s[i] = 'a' + i;
  for (int i = a; i < a + b; i++) s[i] = c;
  int have[26];
  memset(have, 0, 26 * sizeof(int));
  for (long long i = a + b - 1; i >= b; i--) {
    have[s[i] - 'a'] = 1;
  }
  long long i = a + b, j = 0;
  while (i < 2 * a + b) {
    while (have[j]) {
      j++;
    }
    s[i] = j + 'a';
    i++;
    j++;
  }
  for (int i = 2 * a + b; i < T; i++) s[i] = s[i - 1];
  memset(have, 0, 26 * sizeof(int));
  if (l <= r) {
    for (long long i = l; i <= r; i++) {
      if (!have[s[i] - 'a']) {
        count++;
        have[s[i] - 'a'] = 1;
      }
    }
  } else {
    for (long long i = 0; i <= r; i++) {
      if (!have[s[i] - 'a']) {
        count++;
        have[s[i] - 'a'] = 1;
      }
    }
    for (long long i = l; i < T; i++) {
      if (!have[s[i] - 'a']) {
        count++;
        have[s[i] - 'a'] = 1;
      }
    }
  }
  return count;
}
int main() {
  long long t;
  cin >> a >> b >> l >> r;
  l--;
  r--;
  T = 2 * (a + b);
  if (a > b + 1)
    t = 2 * a - b;
  else
    t = a + 1;
  if (r - l >= T)
    ans = t;
  else {
    r %= T;
    l %= T;
    for (int i = 0; i < a; i++) {
      ans = min(Cal('a' + i), ans);
    }
  }
  cout << ans << endl;
  return 0;
}
