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.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.event.TreeSelectionEvent;

public class tr6 {
	static int k;
	static int[] arr;

	public static boolean isValid(int mid) {
		int ans = 0;
		int tmp = 0;
		int c = 0;
		for (int i = 0; i < arr.length - 1; i += 2) {
			if (arr[i] + arr[i + 1] > mid) {
				ans += 2;
			} else {
				ans++;
			}
		}
		if (arr.length % 2 == 1)
			ans++;
		return ans == k;
	}

	public static int binarysearch(int hi, int lo) {
		int ans = 0;
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (isValid(mid)) {
				hi = mid - 1;
				ans = mid;
			} else {
				lo = mid + 1;
			}
		}
		return ans;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		long l = sc.nextLong();
		long r = sc.nextLong();
		long limitx=(long)((double)Math.log10(1e18)/(double)Math.log10(x));
		long limity=(long)((double)Math.log10(1e18)/(double)Math.log10(y));
		ArrayList<Long> al = new ArrayList<>();
		for (int i = 0; i <= limitx; i++) {
			for (int j = 0; j <= limity; j++) {
				long a =(power(y,j)+power(x,i));
				if (a>=l && a<=r) {
					al.add(a);
				}	
			}
		}
		Collections.sort(al);
		long max = 0;
		boolean f = false;
		for (int i = 0; i < al.size() - 1; i++) {
			if (al.get(i) >= l) {
				f = true;
			}
			if (al.get(i) > r) {
				break;
			}
			if (f) {
				if (al.get(i) >= l && al.get(i + 1) >= l && al.get(i) <= r && al.get(i + 1) <= r) {
					max = Math.max((al.get(i + 1) - al.get(i)), max);
				}
				
			}
		}
		if(al.size()!=0) {
		max = Math.max(al.get(0)-l+1, max);
		max = Math.max(r-al.get(al.size()-1)+1,max );
		}
		if(al.size()==0)
			max=r-l+2;
		System.out.println(max-1);
	}
	static long power(long base,long pow) {
		long ans=1;
		if(pow==0)
			return 1;
		for(int y=0;y<pow;y++)
			ans*=base;
		return ans;
	}
	public static class Dragons implements Comparable<Dragons> {
		int x, y;

		public Dragons(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Dragons A) {
			if (x == A.x)
				return A.y - y;
			return x - A.x;
		}

		public String toString() {
			return x + " " + y;
		}
	}

	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();
		}

	}

}