#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  l--;
  if (r - l == 1) {
    cout << "1\n";
    return 0;
  }
  if (r - l >= 2 * a + 2 * b) {
    if (b < a)
      cout << 2 * a - b << "\n";
    else
      cout << a + 1 << "\n";
    return 0;
  }
  vector<int> arr(2 * a + 2 * b);
  l %= arr.size();
  r %= arr.size();
  int p = a - 1;
  if (l > r and r > 0) p = min(r - 1, a - 1);
  for (int i = 0; i < a; i++) arr[i] = i;
  for (int i = a; i < a + b; i++) arr[i] = p;
  int w = min(b, a - 1);
  for (int i = 0; i < w; i++) arr[i + a + b] = i;
  for (int i = 0; i < a - w; i++) arr[i + a + b + w] = i + a;
  for (int i = 2 * a + b; i < 2 * a + 2 * b; i++) arr[i] = arr[2 * a + b - 1];
  vector<bool> st(30);
  for (int i = l; i != r; i = (i + 1) % arr.size()) {
    st[arr[i]] = true;
  }
  int res = 0;
  for (bool e : st) res += e;
  cout << res << "\n";
}
