#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  long long l, h;
  cin >> l >> h;
  long long cont = 1;
  long long resp1 = 0;
  vector<long long> resp;
  resp.push_back(l - 1);
  for (long long i = 0;; i++) {
    long long cont1 = 1;
    for (long long d = 0;; d++) {
      if (cont + cont1 >= l && cont1 + cont <= h) resp.push_back(cont + cont1);
      long long help = cont1;
      cont1 *= y;
      if (cont1 / y != help) break;
      if (cont1 + cont > h) break;
    }
    long long help = cont;
    cont *= x;
    if (cont / x != help) break;
    if ((cont) > h) break;
  }
  resp.push_back(h + 1);
  sort(resp.begin(), resp.end());
  for (long long i = 1; i < resp.size(); i++) {
    resp1 = max(resp1, (resp[i] - resp[i - 1]) - 1);
  }
  cout << resp1 << endl;
  return 0;
}
