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.util.*;

import javax.sound.midi.Synthesizer;
import javax.swing.plaf.synth.SynthSpinnerUI;


public class Fight {
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);
	static ArrayList<Integer>[] adj;
	static boolean[] vis;
	public static boolean a[];
	static int max;
	static int c[];
	public static void main(String[] args) throws IOException {	
	long x=sc.nextLong();
	long y=sc.nextLong();
	long l=sc.nextLong();
	long r=sc.nextLong();
	ArrayList<Long> valid=new ArrayList<>();
	boolean b1=true;
	
	long maxlimit=(long) (1e18+1);
	for (int i = 0; i <=60; i++) {
		for (int j = 0; j <=60; j++) {
			
			long x1=(long)(pow(x,i));
		    if(x1==0) {
		    	break;
		    }
			long x2=pow(y,j);
			if(x2==0) {
		    	break;
		    }
			long max1=x1+x2;
		if(max1>1e18) {
			break;
		}
		else {
			if(max1>=l&&max1<=r) {
			long max=(long) max1;
			valid.add(max);
			}
		}
		}	
	}
	if(r==l&&valid.size()==0) {
		System.out.println(1);
		return;
	}
	else if(r==l) {
		System.out.println(0);
		return;
	}
	valid.add(l-1);
	Collections.sort(valid);
	long ans=0;
	valid.add((long) r+1);
	for (int i = 1; i < valid.size(); i++) {
		ans=Math.max(ans,valid.get(i)-valid.get(i-1)-1);
	}
	
	System.out.println(ans);		
	}
	public static long pow(long x,long y){
		long ans=1;
		while(y-->0) {
		if(ans>1e18/x) {
			return 0;
		}
		else
		ans*=x;
		}
		return ans;
	}

	
	
	static boolean f1;
	private static void  rec(int i, int sum) {
		if(i==5) {
		if(sum==23) {
			f1=true;
		}
		
		}
		
		for (int j = 0; j < 5; j++) {
			
		
		if(!vis[j]) {
		vis[j]=true;
			 rec(i+1,sum+c[j]);rec(i+1,sum-c[j]);rec(i+1,sum*c[j]);
			 vis[j]=false;
		}
		
		}
		}
	static int n;
	static int d[];

    static void permute(int idx, int mask,int sum) {
        if (mask == (1 << n) - 1) {
        	if(primes.contains(d[0]+d[c.length-1])&&primes.contains(d[d.length-1]+d[d.length-2]))
        	{for (int i = 0; i < d.length; i++) {
				if(i==d.length-1) {
					out.print(d[i]);
				}
				
				else
        		out.print(d[i]+" ");
			}
        	out.println();
        	}
        }
    
        if(d[0]!=0&&d[0]!=1) {
        	return;
        }
        if(idx!=0)
        
        
        if(sum!=0&&idx!=1&&idx!=0&&!primes.contains(d[idx-1]+d[idx-2])) {
        	return;
        }
        
        
         
         for (int i = 0; i < n; i++) {
            if ((mask & 1 << i) == 0) {
                d[idx] = c[i];
                      
                permute(idx + 1, mask | 1 << i,d[idx]);
            }
        }
    }
	
	static int min=0;
	static int dfs(int u)
    {
		boolean f=true;
		vis[u]=true;
		for (int b : adj[u]) {
			if(!vis[b]) {
			c[u]+=dfs(b);
			f=false;
			}
		}
		if(f) {
			return c[u]=1;
		}
		
		return c[u];
		
		
		
    }	
		
	
	static int x;
	  static int [] end;
	static int cost=Integer.MAX_VALUE;
	
	static class edge{
		int x; int y;
		public edge(int x1, int y1) {
		x=x1;
		y=y1;
		}
	}
		
		
	
	static HashSet<Integer> primes;
	static int[] isComposite;

	static void sieve(int N)	// O(N log log N) 
	{
		isComposite = new int[N+1];					
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new HashSet<Integer>();
		int curmax=0;
		int ans[]=new int[N+1];

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) 
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				x++;
				ans[i]=x;
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i) {	// j = i * 2 will not affect performance too much, may alter in modified sieve
							ans[j]=x;
						
						isComposite[j] = 1;
								
					}
			} 
		
	}

	
	
	
	



	private static boolean works(long mid,int[] a,int cur,long sum) {
		int i, j;
		for(i = 0, j = a.length - 1; cur> 0 && i <= j;cur--,i++,j--) {
			if(a[i] + a[j] >mid)
			{
			i--;
			}
	}
		return i>j;
	
	}


   
	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 int[] nextIntArr(int n) throws IOException {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = nextInt();
		return arr;
	}

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

	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 void waitForInput() throws InterruptedException {Thread.sleep(1000);}
}
}

