#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
vector<long long> A;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, y, l, r;
  cin >> x >> y >> l >> r;
  long long X = 1, Y = 1;
  for (int i = (0); i < (60); i++) {
    if (X > r) break;
    Y = 1;
    for (int j = (0); j < (60); j++) {
      if (Y > r) break;
      if (l <= X + Y && X + Y <= r) A.push_back(X + Y);
      if (Y * (double)y > 2 * LINF) break;
      Y *= y;
    }
    if (X * (double)x > 2 * LINF) break;
    X *= x;
  }
  A.push_back(l - 1);
  A.push_back(r + 1);
  sort(A.begin(), A.end());
  A.resize(unique(A.begin(), A.end()) - A.begin());
  long long ans = 0;
  for (int i = (1); i < ((int)A.size()); i++) {
    ans = max(ans, A[i] - A[i - 1] - 1);
  }
  cout << ans << endl;
  return 0;
}
