#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 1e5 + 10;
int add(int x, int y) {
  x += y;
  if (x >= 1000000007LL) x -= 1000000007LL;
  return x;
}
int mul(int x, int y) {
  x = (1LL * x * y) % 1000000007LL;
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    long long a, b, l, r, ans;
    cin >> a >> b >> l >> r;
    int d;
    if (a > b)
      d = a + (a - b);
    else {
      d = a + 1;
    }
    vector<int> c(2 * (a + b), 0);
    for (int i = 1; i < a; i++) {
      c[i] = c[i - 1] + 1;
    }
    for (int i = 0; i < b; i++) {
      c[a + i] = c[a + i - 1];
    }
    for (int i = 0; i < min(b, a - 1); i++) {
      c[a + b + i] = c[i];
    }
    int x = c[a - 1];
    for (int i = a + b + min(b, a - 1); i < 2 * a + b; i++) {
      c[i] = x + 1;
      x++;
    }
    for (int i = 2 * a + b; i < 2 * (a + b); i++) {
      c[i] = x;
    }
    l--;
    r--;
    int p = l / (2 * (a + b));
    int q = r / (2 * (a + b));
    l = l % (2 * (a + b));
    r = r % (2 * (a + b));
    cout << endl;
    if (p == q) {
      ans = 0;
      vector<int> y(30, 0);
      for (int i = l; i <= r; i++) {
        y[c[i]] = 1;
      }
      for (int i = 0; i < 30; i++) {
        ans += y[i];
      }
    } else if (p + 1 == q && l > r) {
      ans = 0;
      vector<int> y(30, 0);
      for (int i = 0; i <= r; i++) {
        y[c[i]] = 1;
      }
      for (int i = l; i < 2 * (a + b); i++) {
        y[c[i]] = 1;
      }
      for (int i = 0; i < 30; i++) {
        ans += y[i];
      }
      if (l >= a && l < a + b && r < a - 1 && r > b - 1) {
        ans--;
      }
    } else {
      ans = d;
    }
    cout << ans;
  }
  return 0;
}
