#include <bits/stdc++.h>
using namespace std;
long long unlucky[4000];
long long powx(long long num, long long x);
int main(int argc, char *argv[]) {
  long long x, y, l, r;
  scanf("%I64d%I64d%I64d%I64d", &x, &y, &l, &r);
  long long expx = powx(r, x);
  long long expy;
  int curP = 0;
  long long target;
  long long powOfx = 1;
  long long powOfy;
  unlucky[curP++] = l - 1;
  unlucky[curP++] = r + 1;
  for (long long i = 0; i <= expx; i++) {
    target = r - powOfx;
    expy = powx(target, y);
    powOfy = 1;
    for (long long j = 0; j <= expy; j++) {
      if (powOfx + powOfy >= l) {
        unlucky[curP++] = powOfx + powOfy;
      }
      powOfy *= y;
    }
    powOfx *= x;
  }
  sort(unlucky, unlucky + curP);
  long long maxlen = 0;
  for (int i = 1; i < curP; i++) {
    if (maxlen < unlucky[i] - unlucky[i - 1] - 1) {
      maxlen = unlucky[i] - unlucky[i - 1] - 1;
    }
  }
  printf("%I64d\n", maxlen);
  return 0;
}
long long powx(long long num, long long x) {
  long long retval = 0;
  while (num / x > 0) {
    retval++;
    num = num / x;
  }
  return retval;
}
