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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alexander Tsupko (alexander.tsupko@outlook.com)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            BigInteger x = new BigInteger(in.next());
            BigInteger y = new BigInteger(in.next());
            BigInteger l = new BigInteger(in.next());
            BigInteger r = new BigInteger(in.next());
            List<BigInteger> list = new ArrayList<>();
            BigInteger xx = BigInteger.ONE, yy, sum;
            for (int p = 0; p <= 64; ++p) {
                yy = BigInteger.ONE;
                for (int q = 0; q <= 64; ++q) {
                    sum = xx.add(yy);
                    if (l.compareTo(sum) <= 0 && sum.compareTo(r) <= 0) list.add(sum);
                    yy = yy.multiply(y);
                }
                xx = xx.multiply(x);
                if (xx.compareTo(r) > 0) break;
            }
            list.add(l.subtract(BigInteger.ONE));
            list.add(r.add(BigInteger.ONE));
            Collections.sort(list);
            BigInteger answer = BigInteger.ZERO, current;
            for (int i = 1; i < list.size(); ++i) {
                current = list.get(i).subtract(list.get(i - 1)).subtract(BigInteger.ONE);
                if (current.compareTo(answer) > 0) answer = current;
            }
            out.print(answer);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(Object obj) {
            writer.print(obj);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[1024];
        private int current;
        private int size;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            if (size == -1) throw new InputMismatchException();
            if (current >= size) {
                current = 0;
                try {
                    size = stream.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0) return -1;
            }
            return buffer[current++];
        }

        public String next() {
            int c = read();
            while (isSpaceCharacter(c)) c = read();
            StringBuilder stringBuilder = new StringBuilder();
            do {
                stringBuilder.appendCodePoint(c);
                c = read();
            } while (!isSpaceCharacter(c));
            return stringBuilder.toString();
        }

        private boolean isSpaceCharacter(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

