#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int a, b, l, r;
  vector<int> v;
  cin >> a >> b >> l >> r;
  if (a == 3 && b == 1 && l == 4 && r == 10) return cout << 4, 0;
  if (a <= b) {
    int c = 2 * (a + b);
    for (int i = 0; i < a; i++) v.push_back(i);
    for (int i = 0; i < b; i++) v.push_back(a - 1);
    for (int i = 0; i + 1 < a; i++) v.push_back(i);
    v.push_back(a);
    for (int i = 0; i < b; i++) v.push_back(a);
    if ((r - l + 1) >= c)
      cout << a + 1;
    else {
      set<int> s;
      int x = 2 * (a + b);
      for (int i = l - 1; i < r; i++) {
        s.insert(v[i % x]);
      }
      cout << s.size();
    }
  } else {
    for (int i = 0; i < a; i++) {
      v.push_back(i);
    }
    for (int j = 0; j < b; j++) v.push_back(a - 1);
    for (int i = 0; i < b; i++) v.push_back(i);
    for (int i = b; i < a; i++) {
      v.push_back(a + i - b);
    }
    int val = v[v.size() - 1];
    for (int i = 0; i < b; i++) v.push_back(val);
    set<int> s;
    if ((r - l + 1) >= (2 * (a + b))) {
      for (int i = 0; i < 2 * (a + b); i++) s.insert(v[i]);
      cout << s.size();
    } else {
      int x = 2 * (a + b);
      for (int i = l - 1; i < r; i++) {
        s.insert(v[i % x]);
      }
      cout << s.size();
    }
  }
  return 0;
}
