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.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 	
 
public class Main {
	static PrintWriter pr = new PrintWriter(System.out);
	
	
	
	
	public static void main(String args[]) throws IOException{
		//FileReader in = new FileReader("C:/test.txt");
		
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		long y = sc.nextLong();
		long l = sc.nextLong();
		long r = sc.nextLong();
		TreeSet<Long> set = new TreeSet<Long>();
		long numx=1;
		long numy=1;
		if(numx+numy >=l && numx+numy<=r)
			 set.add(numx+numy);
		for(int i=0; i<=61; i++) {
			
			for(int j=0; j<=61; j++)
			{
				
					if(numx<=1e18-numy) {
						long num = numx+numy;
						 if(num >=l && num<=r)
							 set.add(num);
					} 
					if(numy<=1e18/y) {
						numy*=y;
					}
					else
						break;
			}
			numy=1;
			if(numx<=1e18/x) {
				numx*=x;
				
			}else
				break;	
		}
		
		if(set.size()==0) {
			System.out.println(r-l+1);;
			return;
		}
		long[] nums = new long[set.size()];
		int index=0;
		for(long z:set) {
			nums[index++] = z;
			//pr.println(z);
		}
			
		//pr.println(set.size());
		
		
		long max=0;
		max = Math.max(max, nums[0]-l);
		for(int i=1; i<set.size(); i++) {
			max = Math.max(max,nums[i]-nums[i-1]-1);
		}
		max = Math.max(max, r-nums[nums.length-1]);
		System.out.println(max);
		
		
		pr.flush();
		pr.close();
	}
	
	
	
	
	static class Edge implements Comparable<Edge>
	{
		int u,v,index;
		public Edge(int a, int b, int c) { u = a;v = b; index = c;}
		@Override
		public int compareTo(Edge e) {
			return e.u-u;
		}
		
	}
	
	
	static class Order implements Comparable<Order>
	{
		int time,fine, index;
		public Order(int time, int fine, int index) { this.time = time; this.fine = fine; this.index = index;}
		@Override
		public int compareTo(Order o) {
			if(time*o.fine!=o.time*fine) {
				return time*o.fine-o.time*fine;
			}
			return index-o.index;
		}
		
	}


	
	static class UnionFind {                                              
		int[] p, rank;

		UnionFind(int N) 
		{
			p = new int[N];
			rank = new int[N];
			for (int i = 0; i < N; i++) 
				p[i] = i;
		}

		int findSet(int x) { return p[x] == x ? x : (p[x] = findSet(p[x])); }

		boolean union(int x, int y) 
		{ 
			x = findSet(x);
			y = findSet(y);
			if(x == y)
				return false;

			if (rank[x] > rank[y]) 
				p[y] = x;
			else
			{	
				p[x] = y;
				if(rank[x] == rank[y])
					++rank[y]; 
			} 
			return true;
		}
	}
	
	
	public class pair implements Comparable<pair>{
		int a;
		int b;
		int c;
		public pair(int a, int b) {
			this.a = a;
			this.b = b;
			
		}
		public int compareTo(pair o) {
			if(a!=o.a)
				return a-o.a;
			else 
				return b-o.b;
			
		}
 
	}
	
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String f) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(f));
		}

		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 {
			return Double.parseDouble(next());
		}

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

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public int[] nextIntArray1(int n) throws IOException {
			int[] a = new int[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextInt();
			return a;
		}

		public int[] shuffle(int[] a, int n) {
			int[] b = new int[n];
			for (int i = 0; i < n; i++)
				b[i] = a[i];
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				int t = b[i];
				b[i] = b[j];
				b[j] = t;
			}
			return b;
		}

		public int[] nextIntArraySorted(int n) throws IOException {
			int[] a = nextIntArray(n);
			a = shuffle(a, n);
			Arrays.sort(a);
			return a;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArray1(int n) throws IOException {
			long[] a = new long[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArraySorted(int n) throws IOException {
			long[] a = nextLongArray(n);
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
			Arrays.sort(a);
			return a;
		}
	}
	
	
	
	//
}