#include <bits/stdc++.h>
using namespace std;
int a, b, l, r, sum;
int num(int x) { return x % (a + b); }
bool aOrb(int x) {
  int y = num(x);
  if (y <= a && y >= 1) return true;
  return false;
}
int main() {
  while (~scanf("%d%d%d%d", &a, &b, &l, &r)) {
    sum = 0;
    if (l == r)
      cout << 1 << endl;
    else if (r - l + 1 > 2 * a + b)
      cout << a + 1 + (a > b ? a - b - 1 : 0) << endl;
    else {
      int x = num(l);
      int y = num(r);
      if (!aOrb(l)) {
        if (x > 0 && y < a + b && y > x)
          x = 0, y = 0;
        else if (x == 0)
          y = x + r - l;
        else
          y = r - l - a - b + x, x = 0;
      } else
        y = x + r - l;
      if (x == 0) {
        sum = min(a, y) + 1;
        if (a > b) {
          if (y > a + 2 * b + 1) {
            sum += y - a - 2 * b - 1;
          }
        }
      } else {
        if (y > a)
          sum += a - x + 1;
        else {
          cout << y - x + 1 << endl;
          break;
        }
        if (aOrb(r)) {
          if (a <= b) {
            if (y == 2 * a + b)
              sum = a + 1;
            else {
              sum += y - a - b;
              sum = min(a, sum);
            }
          } else {
            int n = b - x + 1;
            sum += y - a - b;
            if (n > 0) sum -= n;
            sum = min(sum, 2 * a - b);
          }
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
