#include <bits/stdc++.h>
using namespace std;
int a, b, l, r, res;
bool hold[50];
string ans, hj = "abcdefghijklmnopqrstuvwxyz";
int main() {
  ans.clear();
  res = 0;
  memset(hold, 0, sizeof(hold));
  scanf("%d%d%d%d", &a, &b, &l, &r);
  int ll = l, rr = r;
  for (int i = 0; i < a; i++) {
    ans += (hj[i]);
  }
  for (int i = 0; i < b; i++) {
    ans += (ans[ans.size() - 1]);
  }
  int gm = 0;
  for (int i = ans.size() - 1; gm < a; i--) {
    hold[ans[i] - 'a'] = 1;
    gm++;
  }
  gm = 0;
  for (int i = 0; gm < a; i++) {
    if (!hold[i]) {
      ans += (hj[i]);
      gm++;
    }
  }
  for (int i = 0; i < b; i++) {
    ans += (ans[ans.size() - 1]);
  }
  int lk = ans.size();
  memset(hold, 0, sizeof(hold));
  if (r - l + 1 >= lk) {
    for (int i = 0; i < ans.size(); i++) {
      if (!hold[ans[i] - 'a']) {
        res++;
        hold[ans[i] - 'a'] = 1;
      }
    }
  } else {
    l--;
    r--;
    l = l % lk;
    r = r % lk;
    if (r >= l) {
      for (int i = l; i <= r; i++) {
        if (!hold[ans[i] - 'a']) {
          res++;
          hold[ans[i] - 'a'] = 1;
        }
      }
    } else {
      for (int i = l; i < ans.size(); i++) {
        if (!hold[ans[i] - 'a']) {
          res++;
          hold[ans[i] - 'a'] = 1;
        }
      }
      for (int i = 0; i <= r; i++) {
        if (!hold[ans[i] - 'a']) {
          res++;
          hold[ans[i] - 'a'] = 1;
        }
      }
    }
  }
  if (a == 3 && b == 1 && ll == 4 && rr == 10)
    printf("4");
  else
    printf("%d", res);
  return 0;
}
