#include <bits/stdc++.h>
using namespace std;
long long mi(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
int main() {
  long long x, y, l, r, m = 0;
  set<long long> s;
  cin >> x >> y >> l >> r;
  long long l1 = log(r) / log(x), l2 = log(r) / log(y);
  for (int i = 0; i <= l1; i++)
    for (int j = 0; j <= l2; j++) {
      long long x0 = 1, y0 = 1;
      for (int k = 1; k <= i; k++) {
        x0 *= x;
        if (x0 > r) goto loop;
      }
      for (int k = 1; k <= j; k++) {
        y0 *= y;
        if (y0 > r) goto loop;
      }
      if (x0 + y0 >= l && x0 + y0 <= r) s.insert(x0 + y0);
    loop:;
    }
  s.insert(r + 1);
  long long a = l - 1, b;
  for (auto i = s.begin(); i != s.end(); i++) {
    b = *i;
    if (b - a - 1 > m) m = b - a - 1;
    a = b;
  }
  cout << m << endl;
  return 0;
}
