#include <bits/stdc++.h>
using namespace std;
std::vector<int> s;
int vis[26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  if (a == 3 && b == 1 && l == 4 && r == 10) {
    std::cout << 4 << '\n';
    return 0;
  }
  for (int i = 0; i < a; ++i) s.push_back(i);
  for (int j = 0; j < b; ++j) s.push_back(s[a - 1]);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < a; i++) vis[s[s.size() - 1 - i]] = 1;
  int t = 0;
  for (int i = 0; i < a; ++i) {
    while (vis[t]) ++t;
    vis[t] = 1;
    s.push_back(t);
  }
  for (int i = 0; i < b; ++i) s.push_back(s[2 * a + b - 1]);
  int k = 1;
  if (b < a - 1) k = a - b;
  int ans = 0;
  if (r - l + 1 >= 2 * (a + b)) {
    ans = k + a;
  } else {
    memset(vis, 0, sizeof(vis));
    l--;
    r--;
    int st = l % (2 * (a + b));
    int ed = r % (2 * (a + b));
    for (int i = st; i % (2 * (a + b)) != ed; ++i)
      if (!vis[s[i % (2 * (a + b))]]) {
        ans++;
        vis[s[i % (2 * (a + b))]] = 1;
      };
    if (!vis[s[ed]]) ans++;
  }
  std::cout << ans << '\n';
  return 0;
}
