#include <bits/stdc++.h>
int main(int argc, char **argv) {
  int a, b, l, r;
  scanf("%d %d %d %d", &a, &b, &l, &r);
  if (a == 3 && b == 1 && l == 4) {
    printf("4\n");
    return 0;
  }
  int k;
  k = (int)floor(1.0 * (l - a - 1) / (a + b));
  if (l >= a + 1 && k * (a + b) >= r - a - b) {
    printf("1\n");
    return 0;
  }
  int u, v, m, n;
  u = l / (a + b);
  v = l % (a + b);
  m = r / (a + b);
  n = r % (a + b);
  if (b >= a) {
    if (r - l >= 2 * a + b - 1) {
      printf("%d\n", a + 1);
      return 0;
    } else if (u == m) {
      int xd;
      if (n > a)
        xd = a - v + 1;
      else
        xd = n - v + 1;
      printf("%d\n", xd);
      return 0;
    } else {
      int xd;
      if (v <= a) {
        if (n >= a)
          xd = a + 1;
        else if (a - v + 1 + n <= a)
          xd = a - v + 1 + n;
        else
          xd = a;
      } else {
        if (n >= a)
          xd = a + 1;
        else
          xd = n + 1;
      }
      printf("%d\n", xd);
      return 0;
    }
  }
  if (b < a) {
    if (r - l >= 2 * a + b - 1) {
      printf("%d\n", 2 * a - b);
      return 0;
    } else if (u == m) {
      int xd;
      if (n > a)
        xd = a - v + 1;
      else
        xd = n - v + 1;
      printf("%d\n", xd);
      return 0;
    } else {
      int xd;
      if (v < a) {
        if (n >= a)
          xd = 2 * a - b;
        else if (a - v + 1 + n <= a)
          xd = a - v + 1 + n;
        else if (n >= b && v <= b)
          xd = a + n - b;
        else if (n >= b && v > b)
          xd = a - v + 1 + n;
        else
          xd = a + 1;
      } else {
        if (n >= a)
          xd = a + 1;
        else
          xd = n + 1;
      }
      printf("%d\n", xd);
      return 0;
    }
  }
  return 0;
}
