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.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.TreeSet;

/**
 * Created by yash on 04/06/17.
 */
public class B {
    public static void main(String[] args) throws IOException {
//        Reader fileReader = new FileReader(new File("res/B"));
        Reader reader = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(reader);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Solver solver = new Solver();
        solver.solve(br, bw);
        br.close();
        bw.close();
    }

    static class Solver {

        Utils utils;

        Solver() {
            utils = new Utils();
        }

        void solve(BufferedReader br, BufferedWriter bw) throws IOException {
            long[] args = new long[4];
            utils.getLongArray(br.readLine(), args);
            long x1 = args[0];
            long y1 = args[1];
            long l = args[2];
            long r = args[3];

            long x = Long.min(x1, y1);
            long y = Long.max(x1, y1);

            ArrayList<Long> a = new ArrayList<>();
            ArrayList<Long> b = new ArrayList<>();
            a.add(1L);
            b.add(1L);

            long prev = 1;
            for (int i = 1; i <= r; i++) {
                long temp = prev * x;
                if (prev != 0 && temp / prev != x) {
                    break;
                }
                prev = temp;
                if (temp < r) {
                    a.add(temp);
                }
                if (temp >= r)
                    break;
            }

            prev = 1;
            for (int i = 1; i <= r; i++) {
                long temp = prev * y;
                if (prev != 0 && temp / prev != y) {
                    break;
                }
                prev = temp;
                if (temp < r) {
                    b.add(temp);
                }
                if (temp >= r)
                    break;
            }

            TreeSet<Long> vals = new TreeSet<>();

            for (int i = 0; i < a.size(); i++) {
                for (int j = 0; j < b.size(); j++) {
                    long temp = a.get(i) + b.get(j);
                    if (temp >= l && temp <= r) {
                        vals.add(temp);
                    }
                }
            }
            long max = 0;

            if (!vals.isEmpty()) {
                Long[] arr = vals.toArray(new Long[vals.size()]);

                for (int j = 1; j < arr.length; j++) {
                    max = Math.max(arr[j] - arr[j - 1] - 1, max);
                }
                max = Math.max(arr[0] - l, max);
                max = Math.max(r - arr[vals.size() - 1], max);
            } else {
                max = r - l + 1;
            }

            bw.write(max + "\n");
        }
    }

    static class Utils {

        void getLongArray(String s, long a[]) {
            String[] temp = s.split(" ");
            for (int i = 0; i < temp.length; i++) {
                a[i] = getLong(temp[i]);
            }
        }

        void getIntArray(String s, int a[]) {
            String[] temp = s.split(" ");
            for (int i = 0; i < temp.length; i++) {
                a[i] = getInt(temp[i]);
            }
        }

        void getIntArray(String s, int a[], String regex) {
            String[] temp = s.split(regex);
            for (int i = 0; i < temp.length; i++) {
                a[i] = getInt(temp[i]);
            }
        }

        int getInt(String s) {
            return Integer.parseInt(s);
        }

        long getLong(String s) {
            return Long.parseLong(s);
        }

        void printArray(int[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void printArray(Object[] a) {
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();
        }

        void print2DArray(int[][] a) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    System.out.print(a[i][j] + " ");
                }
                System.out.println();
            }
            System.out.println();
        }

        void print2DArray(Object[][] a) {
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[0].length; j++) {
                    System.out.print(a[i][j] + " ");
                }
                System.out.println();
            }
            System.out.println();
        }

    }
}