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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.time.temporal.JulianFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.prefs.BackingStoreException;

import javax.swing.JLabel;

public class answertillD {
	static int minn;

	public static boolean check() {
		return true;
	}

	public static int bin(int i, Long[] Acc, int m) {
		int left = 0;
		int right = Acc.length;
		int mid;
		int ans = 0;
		while (left <= right) {
			mid = (left + right) / 2;
			if (check()) {
				right = mid - 1;
			} else {
				left = mid + 1;
			}
		}
		return ans;
	}

	public static long power(long x,long y){
		long ans=1;
		while(y-->0){
			if(ans<=1e18/x)
				ans*=x;
			else{
				ans=Long.MAX_VALUE;
				break;
			}
		}
		return ans;
	}
	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		PriorityQueue<Long> pq = new PriorityQueue<Long>();
		HashSet<Long> hs = new HashSet<Long>();
		long x=sc.nextLong();
		long y=sc.nextLong();
		long l=sc.nextLong();
		long r=sc.nextLong();
		long sum = 0;
		for (int i = 0; i < 60; i++)
			for (int j = 0; j < 60; j++) {
				sum =  (power(x, i) + power(y, j));
				if (sum > r)
					break;
				if (sum >= l) {
					pq.add(sum);
					hs.add(sum);

				}
			}
		
		long left,right,ans=0;
		if(!hs.contains(l))
			left=l-1;
		else
			left=l;
		while(!pq.isEmpty()){
			right=pq.poll();
			ans=Math.max(ans, right-left-1);
			left=right;
		}
		if(!hs.contains(r))
		right=r+1;
		else
			right=r;
		ans=Math.max(ans, right-left-1);
		System.out.println(ans);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}
