Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. 

For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.

Such interval of years that there are no unlucky years in it is called The Golden Age.

You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.

Input

The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).

Output

Print the maximum length of The Golden Age within the interval [l, r].

If all years in the interval [l, r] are unlucky then print 0.

Examples

Input

2 3 1 10


Output

1


Input

3 5 10 22


Output

8


Input

2 3 3 5


Output

0

Note

In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].

In the second example the longest Golden Age is the interval [15, 22].
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e18 + 1;
long long int inf = 1e15;
void scan(int &x);
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long int string_to_number(string s) {
  long long int x = 0;
  stringstream convert(s);
  convert >> x;
  return x;
}
long long int add(long long int a, long long int b) {
  long long int x = (a + b) % MOD;
  return x;
}
long long int mul(long long int a, long long int b) {
  long long int x = (a * b) % MOD;
  return x;
}
long long int sub(long long int a, long long int b) {
  long long int x = (a - b + MOD) % MOD;
  return x;
}
long long int divi(long long int a, long long int b) {
  long long int x = a;
  long long int y = powermod(b, MOD - 2, MOD);
  long long int res = (x * y) % MOD;
  return res;
}
long long int get(long long int x, long long int r) {
  long long int rr = 1;
  for (int cnt = 0;; cnt++) {
    if (rr > r / x) return cnt;
    rr = rr * x;
  }
}
int main(void) {
  long long int x, y, l, r;
  cin >> x >> y >> l >> r;
  long long int alim = get(x, r);
  long long int blim = get(y, r);
  set<long long int> Set;
  for (int i = 0; i <= alim; i++) {
    long long int lx = powermod(x, i, MOD);
    for (int j = 0; j <= blim; j++) {
      long long int rx = powermod(y, j, MOD);
      if (lx > r - rx) break;
      if (lx + rx >= l) Set.insert(lx + rx);
    }
  }
  Set.insert(l - 1LL);
  Set.insert(r + 1LL);
  long long int res = 0;
  for (auto it = Set.begin(); it != Set.end(); it++) {
    auto jt = it;
    jt++;
    if (jt == Set.end()) break;
    long long int r = *jt, l = *it;
    res = max(res, r - 1LL - l);
  }
  cout << res;
  return 0;
}
void scan(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
