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.*;
	    import java.math.*;
	    import java.util.*;
	    import javax.print.attribute.SetOfIntegerSyntax;
	     
	    public class Main {
	    	private static InputStream stream;
	    	private static byte[] buf = new byte[1024];
	    	private static int curChar;
	    	private static int numChars;
	    	private static SpaceCharFilter filter;
	    	private static PrintWriter pw;
	    	private static long count = 0,mod=1000000007;
	    	private static TreeSet<Integer>ts[]=new TreeSet[200000];
	    	private static HashSet hs=new HashSet();
	     

	    	 public static void main(String[] args) {
		        	InputReader(System.in);
		    		pw = new PrintWriter(System.out); 
		            new Thread(null ,new Runnable(){
		               public void run(){
		                   try{
		                       soln();
		                       pw.close();
		                   } catch(Exception e){
		                       e.printStackTrace();
		                   }
		               }
		           },"1",1<<26).start();
		       }
	     
	     
	    	public static long gcd(long x, long y) {
	    		if (x == 0)
	    			return y;
	    		else
	    			return gcd( y % x,x);
	    	}
	    	
	    	 
	    	// To Get Input
	    	// Some Buffer Methods
	     
	    	public static void InputReader(InputStream stream1) {
	    		stream = stream1;
	    	}
	     
	    	private static boolean isWhitespace(int c) {
	    		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	    	}
	     
	    	private static boolean isEndOfLine(int c) {
	    		return c == '\n' || c == '\r' || c == -1;
	    	}
	     
	    	private static int read() {
	    		if (numChars == -1)
	    			throw new InputMismatchException();
	    		if (curChar >= numChars) {
	    			curChar = 0;
	    			try {
	    				numChars = stream.read(buf);
	    			} catch (IOException e) {
	    				throw new InputMismatchException();
	    			}
	    			if (numChars <= 0)
	    				return -1;
	    		}
	    		return buf[curChar++];
	    	}
	     
	    	private static int nextInt() {
	    		int c = read();
	    		while (isSpaceChar(c))
	    			c = read();
	    		int sgn = 1;
	    		if (c == '-') {
	    			sgn = -1;
	    			c = read();
	    		}
	    		int res = 0;
	    		do {
	    			if (c < '0' || c > '9')
	    				throw new InputMismatchException();
	    			res *= 10;
	    			res += c - '0';
	    			c = read();
	    		} while (!isSpaceChar(c));
	    		return res * sgn;
	    	}
	     
	    	private static long nextLong() {
	    		int c = read();
	    		while (isSpaceChar(c))
	    			c = read();
	    		int sgn = 1;
	    		if (c == '-') {
	    			sgn = -1;
	    			c = read();
	    		}
	    		long res = 0;
	    		do {
	    			if (c < '0' || c > '9')
	    				throw new InputMismatchException();
	    			res *= 10;
	    			res += c - '0';
	    			c = read();
	    		} while (!isSpaceChar(c));
	    		return res * sgn;
	    	}
	     
	    	private static String nextToken() {
	    		int c = read();
	    		while (isSpaceChar(c))
	    			c = read();
	    		StringBuilder res = new StringBuilder();
	    		do {
	    			res.appendCodePoint(c);
	    			c = read();
	    		} while (!isSpaceChar(c));
	    		return res.toString();
	    	}
	     
	    	private static String nextLine() {
	    		int c = read();
	    		while (isSpaceChar(c))
	    			c = read();
	    		StringBuilder res = new StringBuilder();
	    		do {
	    			res.appendCodePoint(c);
	    			c = read();
	    		} while (!isEndOfLine(c));
	    		return res.toString();
	    	}
	     
	    	private static int[] nextIntArray(int n) {
	    		int[] arr = new int[n];
	    		for (int i = 0; i < n; i++) {
	    			arr[i] = nextInt();
	    		}
	    		return arr;
	    	}
	     
	    	private static int[][] next2dArray(int n, int m) {
	    		int[][] arr = new int[n][m];
	    		for (int i = 0; i < n; i++) {
	    			for (int j = 0; j < m; j++) {
	    				arr[i][j] = nextInt();
	    			}
	    		}
	    		return arr;
	    	}
	    	private static char[][] nextCharArray(int n,int m){
	    		char [][]c=new char[n][m];
	    		for(int i=0;i<n;i++){
	    			String s=nextLine();
	    			for(int j=0;j<s.length();j++){
	    				c[i][j]=s.charAt(j);
	    			}
	    		}
	    		return c;
	    	}
	     
	    	private static long[] nextLongArray(int n) {
	    		long[] arr = new long[n];
	    		for (int i = 0; i < n; i++) {
	    			arr[i] = nextLong();
	    		}
	    		return arr;
	    	}
	     
	    	private static void pArray(int[] arr) {
	    		for (int i = 0; i < arr.length; i++) {
	    			pw.print(arr[i] + " ");
	    		}
	    		pw.println();
	    		return;
	    	}
	     
	    	private static void pArray(long[] arr) {
	    		for (int i = 0; i < arr.length; i++) {
	    			pw.print(arr[i] + " ");
	    		}
	    		pw.println();
	    		return;
	    	}
	     
	    	private static void pArray(boolean[] arr) {
	    		for (int i = 0; i < arr.length; i++) {
	    			pw.print(arr[i] + " ");
	    		}
	    		pw.println();
	    		return;
	    	}
	     
	    	private static boolean isSpaceChar(int c) {
	    		if (filter != null)
	    			return filter.isSpaceChar(c);
	    		return isWhitespace(c);
	    	}
	     
	    	private interface SpaceCharFilter {
	    		public boolean isSpaceChar(int ch);
	    	}
	     
	    	//----------------------------------------My Code------------------------------------------------//
	
 
	    	
	    	private static void soln() {
	    	    
	    	 	long x=nextLong();
	    	 	long y=nextLong();
	    	 	long l=nextLong();
	    	 	long r=nextLong();
	    	 	long[] px=new long[(int)Math.floor(Math.log(r)/Math.log(x))+1];
	    	 	long[] py=new long[(int)Math.floor(Math.log(r)/Math.log(y))+1];
	    	 	int lx=px.length;
	    	 	int ly=py.length;
	    	 	px[0]=1;
	    	 	py[0]=1;
	    	 	for(int i=1;i<lx;i++){
	    	 		px[i]=px[i-1]*x;
	    	 	}
	    	 	for(int i=1;i<ly;i++){
	    	 		py[i]=py[i-1]*y;
	    	 	}
	    	 	//System.out.println(lx+" "+px[lx-1]+" "+ly+" "+py[ly-1]);
	    	 	//HashSet<Long> hs=new HashSet<Long>();
	    	 	PriorityQueue<Long> hs=new PriorityQueue<Long>();
	    	 	for(int i=0;i<lx;i++){
	    	 		for(int j=0;j<ly;j++){
	    	 			hs.add(px[i]+py[j]);
	    	 		}
	    	 	}
	    	 	hs.add(r+1);
	    	 	long st=l-1;
	    	 	long ans=0;
	    	 	while(!hs.isEmpty()){
	    	 		long t=hs.poll();
	    	 		//System.out.println(t);
	    	 		if(t>=l && t<=r+1){
	    	 			if((t-st-1)>ans){
	    	 				ans=t-st-1;
	    	 			}
	    	 			st=t;
	    	 		}
	    	 	}
	    	 	pw.println(ans);
	    	 	//pw.println(px[lx-1]+" "+py[ly-1]);
	    	}
	    		//-----------------------------------------The End--------------------------------------------------------------------------//
	    
	    
	    
	    	
	 }
	    	
	   
	    
		class Pair implements Comparable<Pair>{
		     
			int x;
			int y;
			Pair(int idx,int val){
				this.x=idx;
				this.y=val;
			}
			@Override
			public int compareTo(Pair o) {
				// TODO Auto-generated method stub
			//	Sort in increasing order
					if(y>o.y){
						return -1;
					}
					else if(y==o.y){
						return 0;
					}
					else return 1;
                        /*if((x>=y)&&o.x<o.y){
                              return 1;
                        }
                        else if((x<y)&&o.x>=o.y){
                              return -1;
                        }
                        else if((x<y)&&(o.x<o.y)){
                              long m,n;
                            
                             m=Math.min(2*x,y);
                             n=Math.min(2*o.x,o.y);
                            m-=Math.min(x,y);
                            n-=Math.min(o.x,o.y);
                            if(m>=n){
                                  return -1;
                            }
                            else return 1;
                             
                             
                        }
                        else return 0;
				/*if(idx<o.idx)
					return 1;
				else if(idx>o.idx)
					return -1;
				else{
					if(val<o.val)
						return 1;
					else
						return -1;
		
				}*/
				
			}
		
		}