#include <bits/stdc++.h>
using namespace std;
const int dx4[5] = {0, -1, 0, 1, 0};
const int dy4[5] = {0, 0, 1, 0, -1};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int maxn = 2e2 + 3;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
void YES() {
  puts("YES");
  exit(0);
}
void Yes() {
  puts("Yes");
  exit(0);
}
void NO() {
  puts("NO");
  exit(0);
}
void No() {
  puts("No");
  exit(0);
}
void one() {
  puts("-1");
  exit(0);
}
long long x, y, le, ri;
map<long long, long long> hax;
void solve() {
  scanf("%lld%lld%lld%lld", &x, &y, &le, &ri);
  long long cnt = 1;
  for (int i = 0;; i++) {
    long long yk = 1;
    for (int j = 0;; j++) {
      long long res = cnt + yk;
      double tmp = 1.0 * cnt + yk;
      if (tmp > 1e18 || tmp > ri) break;
      if (res >= le && res <= ri) {
        hax[res] = 1;
      } else if (res > ri)
        break;
      tmp = 1.0 * yk * y;
      if (tmp > 1e18 || tmp > ri) break;
      yk = yk * y;
    }
    double tmp = 1.0 * cnt * x;
    if (tmp > 1e18 || tmp > ri) break;
    cnt *= x;
  }
  long long pre = -1;
  long long maxx = 0;
  hax[le - 1]++;
  hax[ri + 1]++;
  for (auto it : hax) {
    if (pre != -1) {
      maxx = max(maxx, it.first - pre - 1);
    }
    pre = it.first;
  }
  cout << maxx << endl;
}
int main() {
  solve();
  return 0;
}
