#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b, l, r;
  cin >> a >> b >> l >> r;
  bool loops_around = (l - 1) % (a + b) >= a && (r - 1) % (a + b) < a;
  vector<string> first_four(4);
  for (int i = 0; i < a; ++i) {
    first_four[0].push_back('a' + i);
  }
  for (int i = 0; i < b; ++i) {
    if (a > b && loops_around) {
      first_four[1].push_back(first_four[0][b]);
    } else {
      first_four[1].push_back(first_four[0].back());
    }
  }
  if (a <= b) {
    for (int i = 0; i < a - 1; ++i) {
      first_four[2].push_back('a' + i);
    }
    first_four[2].push_back(first_four[1].back() + 1);
  } else {
    for (int i = 0; i < b; ++i) {
      first_four[2].push_back('a' + i);
    }
    for (int i = 0; i < a - b; ++i) {
      first_four[2].push_back(first_four[1].back() + i + 1);
    }
  }
  for (int i = 0; i < b; ++i) {
    if (a > b && loops_around) {
      first_four[3].push_back(first_four[2][b]);
    } else {
      first_four[3].push_back(first_four[2].back());
    }
  }
  string ans = first_four[0] + first_four[1] + first_four[2] + first_four[3];
  unordered_set<char> seen;
  for (int i = l; i <= min(r, l + (int)ans.size() - 1); ++i) {
    int pos = (i - 1) % ans.size();
    seen.insert(ans[pos]);
  }
  cout << seen.size() << "\n";
  return 0;
}
