#include <bits/stdc++.h>
using namespace std;
int n, a, b, l, r, bo[1000], t1, t2;
string s;
int main() {
  scanf("%d%d%d%d", &a, &b, &l, &r);
  if (l <= a && r <= a) {
    printf("%d", r - l + 1);
    return 0;
  }
  if (l <= a && r <= a + b) {
    printf("%d", a - l + 1);
    return 0;
  }
  if (a <= l && r <= a + b) {
    printf("1");
    return 0;
  }
  if (a <= b) {
    if (r - l > a + b) {
      printf("%d", a + 1);
      return 0;
    }
    if (r - l == a + b) {
      printf("%d", a);
      return 0;
    }
    t1 = l % (a + b);
    t2 = r % (a + b);
    if (1 <= t1 && t1 <= a && 1 <= t2 && t2 <= a) {
      if (r - l < a)
        printf("%d", r - l + 1);
      else
        printf("%d", min(a - t1 + 2, a) + 1);
      return 0;
    }
    if (1 <= t1 && t1 <= a && (a < t2 || t2 == 0)) {
      printf("%d", a - t1 + 1);
      return 0;
    }
    if ((a < t1 || t1 == 0) && 1 <= t2 && t2 <= a) {
      printf("%d", t2 + 1);
      return 0;
    }
    if ((a < t1 || t1 == 0) && (a < t2 || t2 == 0)) {
      if (r - l < b)
        printf("%d", 1);
      else
        printf("%d", a + 1);
    }
  }
  if (a > b) {
    if (r - l >= 2 * (a + b)) {
      printf("%d", a + a - b);
      return 0;
    }
    t1 = l % (2 * (a + b));
    t2 = r % (2 * (a + b));
    if (a < t1 && t1 <= a + b && 1 <= t2 && t2 <= a) {
      printf("%d", a - b + t2);
      return 0;
    }
    for (int i = 1; i <= a; ++i) s += 'a' + i - 1;
    for (int i = 1; i <= b; ++i) s += 'a' + a - 1;
    for (int i = 1; i <= b; ++i) s += 'a' + i - 1;
    for (int i = 1; i <= a - b; ++i) s += 'a' + a - 1 + i;
    for (int i = 1; i <= b; ++i) s += 'a' + a;
    s = s + s;
    s = " " + s + s;
    if (t1 == 0) t1 += 2 * (a + b);
    if (t1 > t2) t2 += 2 * (a + b);
    int ans = 0;
    for (int i = t1; i <= t2; ++i)
      if (!bo[(int)s[i] - 'a']) bo[(int)s[i] - 'a'] = 1, ans++;
    printf("%d", ans);
  }
}
