#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
string go(int iter, long long a, long long b, long long x) {
  string res;
  vector<int> used(26);
  for (int l = (0); l < (iter); ++l) {
    int j = 0;
    for (int i = (0); i < (a); ++i) {
      while (used[j]) {
        ++j;
      }
      res += 'a' + j;
      ++j;
    }
    char sym = res[res.size() - x];
    for (int i = (0); i < (b); ++i) {
      res += sym;
    }
    for (int i = (0); i < (26); ++i) {
      used[i] = 0;
    }
    for (int i = (0); i < (a); ++i) {
      used[res[res.size() - 1 - i] - 'a'] = 1;
    }
  }
  return res;
}
int solve(int a, int b, int l, int r, int x) {
  string s1 = go(10, a, b, x + 1);
  set<char> ss;
  for (int i = (l); i < (r + 1); ++i) {
    ss.insert(s1[i]);
  }
  return ss.size();
}
int main() {
  long long a, b, l, r;
  cin >> a >> b >> l >> r;
  --l, --r;
  long long start = l / (a + b);
  long long end = r / (a + b);
  if (r - l > 6 * (a + b)) {
    cout << max(a + 1LL, a + a - b) << "\n";
    return 0;
  }
  l -= start * (a + b);
  r -= start * (a + b);
  int res = INT_MAX;
  for (int i = (0); i < (a); ++i) {
    res = min(res, solve(a, b, l, r, i));
  }
  cout << res;
}
