#include <bits/stdc++.h>
using namespace std;
long long int h[1000];
int main() {
  long long int a, b, l, r;
  cin >> a >> b >> l >> r;
  string s[1000];
  long long int x = 0;
  if (a <= b) {
    x = 0;
    for (long long int i = 0; i < a; i++) {
      s[i] = 97 + i;
      x = i;
    }
    x++;
    for (long long int i = 0; i < b; i++) {
      s[x] = s[a - 1];
      x++;
    }
    for (long long int i = 0; i < a - 1; i++) {
      s[x] = s[i];
      x++;
    }
    s[x] = 97 + a;
    x++;
    for (long long int i = 0; i < b; i++) {
      s[x] = 97 + a;
      x++;
    }
  } else if (b < a) {
    x = 0;
    for (long long int i = 0; i < a; i++) {
      s[x] = 97 + i;
      x++;
    }
    for (long long int i = 0; i < b; i++) {
      s[x] = 97 + a - 1;
      x++;
    }
    for (long long int i = 0; i < b; i++) {
      s[x] = s[i];
      x++;
    }
    long long int y = 0;
    for (long long int i = b; i < a; i++) {
      s[x] = 97 + a + y;
      y++;
      x++;
    }
    for (long long int i = 0; i < b; i++) {
      s[x] = 97 + a;
      x++;
    }
  }
  long long int flag = 0;
  if (r - l + 1 < x && (l - 1) % (2 * (a + b)) <= (r - 1) % (2 * (a + b))) {
    for (long long int i = (l - 1) % (2 * (a + b));
         i <= (r - 1) % (2 * (a + b)); i++) {
      h[s[i][0]]++;
    }
  } else {
    if (a >= b) {
      if ((l - 1) % (2 * (a + b)) >= a - 1 &&
          (l - 1) % (2 * (a + b)) <= a + b - 1 &&
          (r - 1) % (2 * (a + b)) == a - 2) {
        flag = 1;
      }
    }
    if ((r - l + 1) >= x - 1) {
      for (long long int i = 0; i < x; i++) {
        h[s[i][0]]++;
      }
    }
    if (l == 0) {
      for (long long int i = 0; i < x; i++) {
        h[s[i][0]]++;
      }
    } else {
      for (long long int i = (l - 1) % (2 * (a + b)); i < x; i++) {
        h[s[i][0]]++;
      }
    }
    for (long long int i = 0; i <= (r - 1) % (2 * (a + b)); i++) {
      h[s[i][0]]++;
    }
  }
  long long int ans = 0;
  for (long long int i = 97; i <= 122; i++) {
    if (h[i] > 0) ans++;
  }
  if (flag == 1)
    cout << ans - 1;
  else
    cout << ans;
  return 0;
}
