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].

/*
 * Code Author: Roshan Shah
 * DA-IICT
 */
import java.io.*;

import java.awt.datatransfer.StringSelection;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;



public class first {

	static double eps=(double)1e-6;
	static long mod=(int)1e9+7;
	public static void main(String args[]){
		InputReader sc = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code----------
		long x =sc.nextLong();
		long y  =sc.nextLong();
		
		long l =sc.nextLong();
		long r =sc.nextLong();
		
		BigInteger o = new BigInteger(String.valueOf(r));
		
		ArrayList<Long> xa = new ArrayList<Long>();
		BigInteger a = new BigInteger("1");
		xa.add((long) 1);
		for(int i=1;;i++)
		{
			a = a.multiply(BigInteger.valueOf(x));
			if(a.compareTo(o)==1)
			{
				break;
			}
			else
			{
				xa.add(a.longValue());
				
			}
			
		}
		
		
		
		ArrayList<Long> yb = new ArrayList<Long>();
		BigInteger b = new BigInteger("1");
		yb.add((long) 1);
		for(int i=1;;i++)
		{
			b = b.multiply(BigInteger.valueOf(y));
			if(b.compareTo(o)==1)
			{
				break;
			}
			else
			{
				yb.add(b.longValue());
			}
			
		}
		
		
		ArrayList<Long> fin = new ArrayList<Long>();
		
		long tot;
		for(int i=0;i<xa.size();i++)
		{
			for(int j=0;j<yb.size();j++)
			{
				tot = xa.get(i)+yb.get(j);
				if(tot<=r && tot>=l)
				{
				if(!fin.contains(tot))	
				fin.add(tot);
				}
			}		
		}
		
		Collections.sort(fin);
		
		long max =0;
		long check=0;
		for(int i=1;i<fin.size();i++)
		{
			check = fin.get(i)-fin.get(i-1)-1;
			if(check>max)
				max =check;
		}
		
		if(fin.size()>=1)
		{
			check = fin.get(0)-l;
			if(check>max)
				max =check;
		}
		
		if(fin.size()>=1)
		{
			check = r-fin.get(fin.size()-1);
			if(check>max)
				max =check;
		}
		
		if(fin.size()==0)
			max =r-l+1;
		
		out.println(max);
		
		//---------------------------------
		out.close();
	}
	
	static class Pair implements Comparable<Pair> {
		long money;
		long value;
		//long w;
		public Pair(long u, long v) {
			this.money = u;
			this.value = v;
		}
 
		public int hashCode() {
			int hu = (int) (money ^ (money >>> 32));
			int hv = (int) (value ^ (value >>> 32));
			return 31 * hu + hv;
		}
 
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair) o;
				return p.money == money && p.value == value;
			}
			return false;
		}
 
		public int compareTo(Pair other) {
			return Long.compare(money, other.money) != 0 ? Long.compare(money, other.money) : Long.compare(value, other.value);
		}
 
		public String toString() {
			return "[u=" + money + ", v=" + value + "]";
		}
	}
	
	
	
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	
	
	
	static long pow(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	
	
	
	static long pow(long n,long p)
	{
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;	    
		    p >>=1;
		    n*=n;	    
		}
		return result;
	}
	
	
	
	
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}

	
	
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public double nextDouble() {
	          return Double.parseDouble(next());
	      }
	}
	
} 