#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y, a[5005], num1, num2, l, r, k, key, maxm, i, j;
  while (scanf("%lld%lld%lld%lld", &x, &y, &l, &r) != EOF) {
    num1 = 1;
    k = 0;
    for (i = 0; i <= 60; i++) {
      if (x <= (1000000000000000050 / num1))
        num1 *= x;
      else
        break;
      if (i == 0) num1 = 1;
      num2 = 1;
      for (j = 0; j <= 60; j++) {
        if (y <= (1000000000000000050 / num2)) {
          num2 *= y;
          if (j == 0) num2 = 1;
          if (num1 + num2 <= 1000000000000000050) a[k++] = num1 + num2;
        } else
          break;
      }
    }
    sort(a, a + k);
    key = 0;
    maxm = 0;
    x = l;
    for (i = 0; i < k; i++) {
      if (a[i] >= l && a[i] <= r) {
        if (!key) {
          key = 1;
          if (a[i] - x > maxm) maxm = a[i] - x;
          x = a[i];
        } else {
          if (a[i] - x - 1 > maxm) maxm = a[i] - x - 1;
          x = a[i];
        }
      }
    }
    if (!key)
      maxm = r - l + 1;
    else {
      if (x < r) maxm = max(maxm, r - x);
    }
    printf("%lld\n", maxm);
  }
  return 0;
}
