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].
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    String fileName = "";
    //////////////////////    SOLUTION   SOLUTION  SOLUTION    //////////////////////////////
    Long INF = Long.MAX_VALUE;
    int MODULO = 1000_000_000 + 7;
    long MAX_VALUE = 1000l*1000*1000*1000*1000*1000*5;
    int[][] steps = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    private final static Random rnd = new Random();
    double eps = 1e-1;

    ArrayList<Integer>[] graph;
    int[] distFromRoot;
    int[] distFromX;
    int[] maxDistFromRoot;
    boolean[] used;
    int ans = -1;
    void solve() throws IOException {
        long x = readLong();
        long y = readLong();
        long l = readLong();
        long r = readLong();
        ArrayList<Long> list1 = new ArrayList<>();
        ArrayList<Long> list2 = new ArrayList<>();
        long cur = 1;
        for (int i=0; i < 70; ++i){
            list1.add(cur);
            if ((BigInteger.valueOf(cur).multiply(BigInteger.valueOf(x))).compareTo(BigInteger.valueOf(MAX_VALUE)) >= 0) break;
            cur *= x;
        }
        cur = 1;
        for (int i=0; i < 70; ++i){
            list2.add(cur);
            if ((BigInteger.valueOf(cur).multiply(BigInteger.valueOf(y))).compareTo(BigInteger.valueOf(MAX_VALUE))>= 0) break;
            cur *= y;
        }
        ArrayList<Long> resList = new ArrayList<>();
        resList.add(l-1);
        resList.add(r+1);
        for (int i=0; i<list1.size(); ++i){
            for (int j=0; j<list2.size(); ++j){
                long sum = list1.get(i) + list2.get(j);
                if (sum >= l && sum <= r){
                    resList.add(sum);
                };
            }
        }
        Collections.sort(resList);
        long ans = 0;
        for (int i=1; i<resList.size(); ++i) ans = Math.max(ans, resList.get(i) - resList.get(i-1) - 1);
        out.println(ans);
    }
    class SegmentTree {
        long[][] t;

        SegmentTree(long[] b, int n) {
            t = new long[n * 4][];
            build(b, 1, 1, n);
        }

        void build(long[] b, int v, int tl, int tr) {
            if (tl > tr) return;
            if (tl == tr) {
                t[v] = new long[1];
                t[v][0] = b[tl];
                return;
            }
            int tm = (tl + tr) / 2;
            build(b, 2 * v, tl, tm);
            build(b, 2 * v + 1, tm + 1, tr);
            t[v] = new long[tr - tl + 1];
            for (int i = tl; i <= tr; ++i)
                t[v][i - tl] = i <= tm ? t[2 * v][i - tl] : t[2 * v + 1][i - tm - 1];
            Arrays.sort(t[v]);
        }

        long get(int v, int tl, int tr, int l, int r, long minLeft) {
            if (l > r) return 0;
            if (tl == l && tr == r) {
                int left = -1;
                int right = t[v].length;
                while (right - left > 1) {
                    int mid = (right + left) / 2;
                    if (t[v][mid] <= minLeft) left = mid;
                    else right = mid;
                }
                return t[v].length - left - 1;
            }
            int tm = (tl + tr) / 2;
            return get(2 * v, tl, tm, l, Math.min(tm, r), minLeft) + get(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r, minLeft);
        }
    }
        long binPow(long a, long b, long m) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return ((a % m) * (binPow(a, b - 1, m) % m)) % m;
        } else {
            long c = binPow(a, b / 2, m);
            return (c * c) % m;
        }

    }

    class Fenwik {
        int[] t;
        int n;
        Fenwik(int n){
            t = new int[n];
            this.n = n;
        }

        void inc(int r, int delta){
            for (; r < n; r = r | (r + 1)) t[r] += delta;
        }
        int getSum(int r){
            int res = 0;
            for (; r >=0; r = (r & (r + 1) ) - 1) res += t[r];
            return res;
        }
    }
    boolean isPrime(int n){
        for (int i=2; i*i<=n; ++i){
            if (n%i==0) return false;
        }
        return true;
    }
    class Edge{
        int from, to;
        long dist;
        public Edge(int to, long dist) {
            this.to = to;
            this.dist = dist;
        }
    }


    class Number implements Comparable<Number>{
        int x, cost;
        Number(int x, int cost){
            this.x = x;
            this.cost = cost;
        }

        @Override
        public int compareTo(Number o) {
            return Integer.compare(this.cost, o.cost);
        }
    }



    ///////////////////////////////////////////////////////////////////////////////////////////

    class Dsu{
        int[] parent;
        int countSets;
        Dsu(int n){
            parent = new int[n];
            countSets = n;
            for (int i=0; i<n; ++i){
                parent[i] = i;
            }
        }
        int findSet(int a){
            if (a == parent[a]) return a;
            parent[a] = findSet(parent[a]);
            return parent[a];
        }
        void unionSets(int a, int b){
            a = findSet(a);
            b = findSet(b);
            if (a != b){
                parent[a] = b;
                countSets--;
            }
        }
    }

    class SparseTable{
        int[][] rmq;
        int[] logTable;
        int n;
        SparseTable(int[] a){
            n = a.length;
            logTable = new int[n+1];
            for(int i = 2; i <= n; ++i){
                logTable[i] = logTable[i >> 1] + 1;
            }
            rmq = new int[logTable[n] + 1][n];
            for(int i=0; i<n; ++i){
                rmq[0][i] = a[i];
            }

            for(int k=1; (1 << k) < n; ++k){
                for(int i=0; i + (1 << k) <= n; ++i){
                    int max1 = rmq[k - 1][i];
                    int max2 = rmq[k-1][i + (1 << (k-1))];
                    rmq[k][i] = Math.max(max1, max2);
                }
            }
        }

        int max(int l, int r){
            int k = logTable[r - l];
            int max1 = rmq[k][l];
            int max2 = rmq[k][r - (1 << k) + 1];
            return Math.max(max1, max2);
        }
    }
    long checkBit(long mask, int bit){
        return (mask >> bit) & 1;
    }

    static int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }
    boolean isLower(char c){
        return c >= 'a' && c <= 'z';
    }

    ////////////////////////////////////////////////////////////



    int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a%b);
    }
    long gcd(long a, long b){
        return b == 0 ? a : gcd(b, a%b);
    }
    double binPow(double a, int pow){
        if (pow == 0) return 1;
        if (pow % 2 == 1) {
            return a * binPow(a, pow - 1);
        } else {
            double c = binPow(a, pow / 2);
            return c * c;
        }
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) min = Math.min(min, value);
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) max = Math.max(max, value);
        return max;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        new Main().run();
    }

    void run() throws NumberFormatException, IOException {
        solve();
        out.close();
    };

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok;
    String delim = " ";

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }

        }
        tok = new StringTokenizer("");
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) {
                return null;
            }

            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken();
    }

    int readInt() throws NumberFormatException, IOException {
        return Integer.parseInt(readString());
    }
    byte readByte() throws NumberFormatException, IOException {
        return Byte.parseByte(readString());
    }
    int[] readIntArray (int n) throws NumberFormatException, IOException {
        int[] a = new int[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    Integer[] readIntegerArray (int n) throws NumberFormatException, IOException {
        Integer[] a = new Integer[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    long readLong() throws NumberFormatException, IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(readString());
    }
}