#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long INFF = 1e18;
const int INF = 1e9;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 7;
bool ck[30];
char s[MAX];
int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  ;
  int l, r;
  scanf("%d %d", &l, &r);
  ;
  int len = r - l + 1;
  int ans = 111;
  if (a <= b) {
    if (len >= 2 * (a + b))
      ans = a + 1;
    else {
      for (int i = 0; i < (a); ++i) s[i] = 'a' + i;
      for (int i = 0; i < (b); ++i) s[i + a] = s[a - 1];
      for (int i = 0; i < (a); ++i) s[i + a + b] = 'a' + i;
      s[2 * a + b - 1] = 'a' + a;
      for (int i = 0; i < (b); ++i) s[i + 2 * a + b] = s[2 * a + b - 1];
      l = (l - 1) % (2 * (a + b));
      r = (r - 1) % (2 * (a + b));
      if (r < l) r += 2 * (a + b);
      ans = 0;
      for (int i = (l); i < (r + 1); ++i) {
        if (!ck[s[i % (2 * (a + b))] - 'a']) {
          ans++;
          ck[s[i % (2 * (a + b))] - 'a'] = 1;
        }
      }
    }
  } else {
    if (len >= 2 * (a + b))
      ans = 2 * a - b;
    else {
      l = (l - 1) % (2 * (a + b));
      r = (r - 1) % (2 * (a + b));
      if (r < l) r += 2 * (a + b);
      for (int p1 = (b); p1 < (a); ++p1)
        for (int p2 = (b); p2 < (a); ++p2) {
          int val = 0;
          for (int i = 0; i < (a); ++i) s[i] = 'a' + i;
          for (int i = 0; i < (b); ++i) s[i + a] = s[p1];
          for (int i = 0; i < (b); ++i) s[i + a + b] = 'a' + i;
          for (int i = 0; i < (a - b); ++i) s[i + a + 2 * b] = 'a' + i + a;
          for (int i = 0; i < (b); ++i) s[i + 2 * a + b] = s[a + b + p2];
          memset(ck, 0, sizeof(ck));
          ;
          for (int i = (l); i < (r + 1); ++i) {
            if (!ck[s[i % (2 * (a + b))] - 'a']) {
              val++;
              ck[s[i % (2 * (a + b))] - 'a'] = 1;
            }
          }
          ans = min(ans, val);
        }
    }
  }
  printf("%d\n", ans);
  return 0;
}
