#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
struct Solution {
  Solution() {}
  void solveCase();
};
void Solution::solveCase() {
  ll x, y, l, r;
  cin >> x >> y >> l >> r;
  vector<ll> vecc;
  ll a = 1;
  while (true) {
    ll b = 1;
    if (b > r) break;
    while (true) {
      if (a + 0.0 + b >= LLONG_MAX) break;
      if (a + b > r) break;
      vecc.push_back(a + b);
      if (b * 1.0 * y >= LLONG_MAX) break;
      b *= y;
    }
    if (a * 1.0 * x >= LLONG_MAX) break;
    a *= x;
  }
  vecc.push_back(l - 1);
  vecc.push_back(r + 1);
  sort(vecc.begin(), vecc.end());
  vecc.erase(unique(vecc.begin(), vecc.end()), vecc.end());
  ll res = 0;
  auto it = lower_bound(vecc.begin(), vecc.end(), l);
  ;
  while (it != vecc.end()) {
    if (l > r) break;
    while (it != vecc.end() && *it == l) {
      ++it;
      ++l;
    }
    ll r1 = r + 1;
    auto it2 = upper_bound(vecc.begin(), vecc.end(), l);
    if (it2 != vecc.end()) r1 = min(*it2, r1);
    ;
    res = max(res, r1 - l);
    l = max(l + 1, r1 + 1);
    ;
    it = lower_bound(vecc.begin(), vecc.end(), l);
  }
  cout << res << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  Solution mySolver;
  for (int i = 1; i <= t; ++i) {
    mySolver.solveCase();
  }
  return 0;
}
