#include <bits/stdc++.h>
bool contained(std::vector<int> v, int x) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == x) {
      return true;
    }
  }
  return false;
}
int main() {
  int a, b;
  long long int l, r;
  scanf("%d %d %lld %lld", &a, &b, &l, &r);
  int mod = 2 * (a + b);
  if (r - l + 1 >= mod) {
    l = 1;
    r = mod - 1;
  } else {
    l = l % mod;
    r = r % mod;
    if (l > r) {
      r += mod;
    }
  }
  int s[mod], t[mod];
  for (int i = 0; i < a; i++) {
    s[i] = i;
    t[i] = i;
  }
  for (int i = a; i < a + b; i++) {
    if (a > b) {
      s[i] = s[b];
    } else {
      s[i] = a - 1;
    }
    t[i] = a - 1;
  }
  if (a > b) {
    for (int i = 0; i < b; i++) {
      s[a + b + i] = i;
      t[a + b + i] = i;
    }
    for (int i = a + 2 * b; i < 2 * a + b; i++) {
      s[i] = i - 2 * b;
      t[i] = i - 2 * b;
    }
  } else {
    int i = 0;
    while (i < a - 1) {
      s[a + b + i] = i;
      t[a + b + i] = i;
      i++;
    }
    s[2 * a + b - 1] = a;
    t[2 * a + b - 1] = a;
  }
  for (int i = 2 * a + b; i < 2 * (a + b); i++) {
    if (a > b) {
      s[i] = s[2 * (a + b) - a];
    } else {
      s[i] = s[2 * a + b - 1];
    }
    t[i] = s[2 * a + b - 1];
  }
  std::vector<int> v;
  std::vector<int> w;
  int count1 = 0;
  int count2 = 0;
  for (int i = l - 1; i < r; i++) {
    if (contained(v, s[i % mod]) == false) {
      v.push_back(s[i % mod]);
      count1 += 1;
    }
    if (contained(w, t[i % mod]) == false) {
      w.push_back(t[i % mod]);
      count2 += 1;
    }
  }
  if (count1 > count2) {
    std::cout << count2 << '\n';
  } else {
    std::cout << count1 << '\n';
  }
}
