#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp& x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int buf[22];
template <typename Tp>
inline void write(Tp x) {
  int p = 0;
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x == 0)
    buf[++p] = 0;
  else
    while (x) {
      buf[++p] = x % 10;
      x /= 10;
    }
  for (int i = p; i; i--) putchar('0' + buf[i]);
}
int a, b, l, r, ans, T;
bool used[30];
char s[100];
inline int solve(char ch) {
  int ret = 0;
  for (int i = 0; i < a; i++) s[i] = 'a' + i;
  for (int i = a; i < a + b; i++) s[i] = ch;
  memset(used, 0, sizeof(used));
  for (int i = b; i < a + b; i++) used[s[i] - 'a'] = true;
  int now = 0;
  for (int i = a + b; i < 2 * a + b; i++) {
    while (used[now]) now++;
    s[i] = now + 'a';
    now++;
  }
  for (int i = 2 * a + b; i < T; i++) s[i] = s[i - 1];
  memset(used, 0, sizeof(used));
  if (l <= r) {
    for (int i = l; i <= r; i++) {
      if (!used[s[i] - 'a']) {
        ret++;
        used[s[i] - 'a'] = true;
      }
    }
  } else {
    for (int i = 0; i <= r; i++) {
      if (!used[s[i] - 'a']) {
        ret++;
        used[s[i] - 'a'] = true;
      }
    }
    for (int i = l; i < T; i++) {
      if (!used[s[i] - 'a']) {
        ret++;
        used[s[i] - 'a'] = true;
      }
    }
  }
  s[a + b << 1] = '\0';
  return ret;
}
int main() {
  read(a);
  read(b);
  read(l);
  read(r);
  l--;
  r--;
  if (a <= b)
    ans = a + 1;
  else
    ans = 2 * a - b;
  T = (a + b) << 1;
  if (r - l + 1 < T) {
    r %= T, l %= T;
    for (int i = 0; i < a; i++) {
      ans = min(ans, solve(i + 'a'));
    }
  }
  printf("%d\n", ans);
  return 0;
}
