#include <bits/stdc++.h>
using namespace std;
long long int arrx[100];
long long int arry[100];
long long int arr[10000];
map<long long int, bool> M;
void parr(long long int a[], long long int n);
int main() {
  long long int x, y, l, r, ss, siz, sizx, sizy, mulx, muly, start, ans, fin,
      ran, tempx, tempy, i, j, temp;
  bool fx, fy;
  scanf("%lld", &x);
  scanf("%lld", &y);
  scanf("%lld", &l);
  scanf("%lld", &r);
  sizx = 0;
  sizy = 0;
  mulx = 1;
  muly = 1;
  tempx = r / x;
  tempy = r / y;
  fx = 1;
  fy = 1;
  while (1) {
    if (fx) {
      arrx[sizx] = mulx;
      sizx++;
    }
    if (fy) {
      arry[sizy] = muly;
      sizy++;
    }
    if (mulx > tempx && muly > tempy) break;
    if (mulx <= tempx) {
      mulx = mulx * x;
    } else
      fx = 0;
    if (muly <= tempy) {
      muly = muly * y;
    } else
      fy = 0;
  }
  siz = 0;
  for (i = 0; i < sizx; i = i + 1) {
    temp = r - arrx[i];
    for (j = 0; j < sizy; j = j + 1) {
      if (arry[j] > temp) break;
      ss = arrx[i] + arry[j];
      if (ss < l) continue;
      if (M[ss]) continue;
      arr[siz] = ss;
      M[ss] = 1;
      siz++;
    }
  }
  sort(arr, arr + siz);
  start = l;
  ans = 0;
  for (i = 0; i < siz; i = i + 1) {
    fin = arr[i] - 1;
    ran = fin - start + 1;
    ans = max(ans, ran);
    start = arr[i] + 1;
  }
  ran = r - start + 1;
  ans = max(ans, ran);
  printf("%lld\n", ans);
  return 0;
}
void parr(long long int a[], long long int n) {
  long long int i;
  for (i = 0; i < n; i = i + 1) {
    printf("%lld ", a[i]);
  }
  printf("\n");
}
