import java.io.*;
import java.util.StringTokenizer;

public class Main {

    BufferedReader reader;
    StringTokenizer tok;
    PrintWriter out;

    String nextToken() throws IOException {
        if (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(reader.readLine());
        }
        return tok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    void open() throws FileNotFoundException {
//        reader = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
//        out = new PrintWriter("output.txt");
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    void close() {
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.open();
        main.solve();
//        main.close();
    }

    private void solve() throws IOException {
        long number = nextLong();
        long first = 1;
        long second = 2;
        long answer = 0;
        while (!(first <= number && number <= second - 1)) {
            long next = first + second;
            first = second;
            second = next;
            answer++;
        }
        System.out.println(answer);
    }

}


import java.awt.Point;
import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.MathContext;
import java.util.*;
import java.util.jar.Attributes.Name;
import java.util.logging.Level;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.json.simple.parser.JSONParser;

public class TestClass {

static long mod ;
static char[] ans;
static long[] F;
static long[] IF;
static long[] lazy;
static int[] W;
static int index;
static int[] c;
static int[][] Batman;
static ArrayList<Integer>[] maps;
static int[] Size;
static ArrayList<String> Q;
static HashMap<String,Boolean> bad_words;

static class Batman{

	   String topic;
	   HashMap<String,Integer> question;
	   ArrayList<String> Q;

	   public Batman(String topic ,HashMap<String,Integer> question, ArrayList<String> Q){

		     this.topic = topic;
		     this.question = question;
		     this.Q = Q;

	   }
}
private static final String[] categories = { "gis", "security",
	"photo", "mathematica", "unix", "wordpress", "scifi",
	"electronics", "android", "apple" };

private static final String[] stopWordsList = { "a's", "able", "about",
	"above", "according", "accordingly", "across", "actually",
	"after", "afterwards", "again", "against", "ain't", "all",
	"allow", "allows", "almost", "alone", "along", "already",
	"also", "although", "always", "am", "among", "amongst", "an",
	"and", "another", "any", "anybody", "anyhow", "anyone",
	"anything", "anyway", "anyways", "anywhere", "apart", "appear",
	"appreciate", "appropriate", "are", "aren't", "around", "as",
	"aside", "ask", "asking", "associated", "at", "available",
	"away", "awfully", "be", "became", "because", "become",
	"becomes", "becoming", "been", "before", "beforehand",
	"behind", "being", "believe", "below", "beside", "besides",
	"best", "better", "between", "beyond", "both", "brief", "but",
	"by", "c'mon", "c's", "came", "can", "can't", "cannot", "cant",
	"cause", "causes", "certain", "certainly", "changes",
	"clearly", "co", "com", "come", "comes", "concerning",
	"consequently", "consider", "considering", "contain",
	"containing", "contains", "corresponding", "could", "couldn't",
	"course", "currently", "definitely", "described", "despite",
	"did", "didn't", "different", "do", "does", "doesn't", "doing",
	"don't", "done", "down", "downwards", "during", "each", "edu",
	"eg", "eight", "either", "else", "elsewhere", "enough",
	"entirely", "especially", "et", "etc", "even", "ever", "every",
	"everybody", "everyone", "everything", "everywhere", "ex",
	"exactly", "example", "except", "far", "few", "fifth", "first",
	"five", "followed", "following", "follows", "for", "former",
	"formerly", "forth", "four", "from", "further", "furthermore",
	"get", "gets", "getting", "given", "gives", "go", "goes",
	"going", "gone", "got", "gotten", "greetings", "had", "hadn't",
	"happens", "hardly", "has", "hasn't", "have", "haven't",
	"having", "he", "he's", "hello", "help", "hence", "her",
	"here", "here's", "hereafter", "hereby", "herein", "hereupon",
	"hers", "herself", "hi", "him", "himself", "his", "hither",
	"hopefully", "how", "howbeit", "however", "i'd", "i'll", "i'm",
	"i've", "ie", "if", "ignored", "immediate", "in", "inasmuch",
	"inc", "indeed", "indicate", "indicated", "indicates", "inner",
	"insofar", "instead", "into", "inward", "is", "isn't", "it",
	"it'd", "it'll", "it's", "its", "itself", "just", "keep",
	"keeps", "kept", "know", "known", "knows", "last", "lately",
	"later", "latter", "latterly", "least", "less", "lest", "let",
	"let's", "like", "liked", "likely", "little", "look",
	"looking", "looks", "ltd", "mainly", "many", "may", "maybe",
	"me", "mean", "meanwhile", "merely", "might", "more",
	"moreover", "most", "mostly", "much", "must", "my", "myself",
	"name", "namely", "nd", "near", "nearly", "necessary", "need",
	"needs", "neither", "never", "nevertheless", "new", "next",
	"nine", "no", "nobody", "non", "none", "noone", "nor",
	"normally", "not", "nothing", "novel", "now", "nowhere",
	"obviously", "of", "off", "often", "oh", "ok", "okay", "old",
	"on", "once", "one", "ones", "only", "onto", "or", "other",
	"others", "otherwise", "ought", "our", "ours", "ourselves",
	"out", "outside", "over", "overall", "own", "particular",
	"particularly", "per", "perhaps", "placed", "please", "plus",
	"possible", "presumably", "probably", "provides", "que",
	"quite", "qv", "rather", "rd", "re", "really", "reasonably",
	"regarding", "regardless", "regards", "relatively",
	"respectively", "right", "said", "same", "saw", "say",
	"saying", "says", "second", "secondly", "see", "seeing",
	"seem", "seemed", "seeming", "seems", "seen", "self", "selves",
	"sensible", "sent", "serious", "seriously", "seven", "several",
	"shall", "she", "should", "shouldn't", "since", "six", "so",
	"some", "somebody", "somehow", "someone", "something",
	"sometime", "sometimes", "somewhat", "somewhere", "soon",
	"sorry", "specified", "specify", "specifying", "still", "sub",
	"such", "sup", "sure", "t's", "take", "taken", "tell", "tends",
	"th", "than", "thank", "thanks", "thanx", "that", "that's",
	"thats", "the", "their", "theirs", "them", "themselves",
	"then", "thence", "there", "there's", "thereafter", "thereby",
	"therefore", "therein", "theres", "thereupon", "these", "they",
	"they'd", "they'll", "they're", "they've", "think", "third",
	"this", "thorough", "thoroughly", "those", "though", "three",
	"through", "throughout", "thru", "thus", "to", "together",
	"too", "took", "toward", "towards", "tried", "tries", "truly",
	"try", "trying", "twice", "two", "un", "under",
	"unfortunately", "unless", "unlikely", "until", "unto", "up",
	"upon", "us", "use", "used", "useful", "uses", "using",
	"usually", "value", "various", "very", "via", "viz", "vs",
	"want", "wants", "was", "wasn't", "way", "we", "we'd", "we'll",
	"we're", "we've", "welcome", "well", "went", "were", "weren't",
	"what", "what's", "whatever", "when", "whence", "whenever",
	"where", "where's", "whereafter", "whereas", "whereby",
	"wherein", "whereupon", "wherever", "whether", "which",
	"while", "whither", "who", "who's", "whoever", "whole", "whom",
	"whose", "why", "will", "willing", "wish", "with", "within",
	"without", "won't", "wonder", "would", "wouldn't", "yes",
	"yet", "you", "you'd", "you'll", "you're", "you've", "your",
	"yours", "yourself", "yourselves", "zero" };

public static long pow(long a , long b){

	   long o=1;

	   while(b>0){

		    if((b&1)!=0) o*=a;

		    a*=a;
		    b/=2;
		    a%=mod;
		    o%=mod;
	   }

	   return o;
}

public static long get_me_baby(int n , int[] A){

	    long ways = F[n];

	    for(int i=0;i<A.length;i++)
	    	ways = (ways*IF[A[i]])%mod;

	    return ways;

}

public static void google_me(int x , ArrayList<Point>[] P){

	 for(int i=0;i<P[x].size();i++){

		  int a = P[x].get(i).x;
		  int b = P[x].get(i).y;

		  if(c[a]==-1){

			  c[a] = c[x]^b;
			  google_me(a, P);
		  }else{

			  int temp = c[x]^b;
			  if(c[a]!=temp) index++;
		  }
	 }
}

public static int parent(int i){

	return Size[i] = Size[i]==i ? i:parent(Size[i]);
}

public static HashMap<String,Integer> wordcount(String S){

	 StringTokenizer sr = new StringTokenizer(S);
	 Q = new ArrayList<String>();
	 HashMap<String,Integer> count = new HashMap<String, Integer>();
	 while(sr.hasMoreTokens()){
		 String a = sr.nextToken();
		 if(bad_words.containsKey(a)) continue;
		 if(count.containsKey(a)) count.put(a,count.get(a)+1);
		 else{ count.put(a,1); Q.add(a);}
	 }

	 return count;

}

public static void main(String args[] ) throws java.lang.Exception {

InputStream inputStream = System.in;
InputReader in = new InputReader(inputStream);

//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
//Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
// PrintWriter pw = new PrintWriter(new FileWriter("C:\\Users\\Sompathak\\Desktop\\output.txt"));
//InputStream inputStream = System.in;
//InputReader in = new InputReader(inputStream);
//Scanner in = new Scanner(new InputStreamReader(System.in));
//Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.java"));
//we can we will ??? !!!!!! SOM RISES
//long startTime = System.currentTimeMillis();
//long startTime = System.currentTimeMillis();

int n = in.nextInt();
int[] A = new int[n];
for(int i=0;i<n;i++) A[i] = in.nextInt();
boolean found = false;
 for(int i=0;i<n;i++)
	 for(int j=0;j<n;j++)
		 for(int k=0;k<n;k++){

			 if(A[i]==A[j] || A[i]==A[k] || A[j]==A[k]) continue;
			 int x = Math.abs(A[i]-A[j]);
			 int y=  Math.abs(A[i]-A[k]);
	         int z=  Math.abs(A[j]-A[k]);
	         if(x>2 || y>2 || z>2) continue;
	         found = true;

		 }
 if(found) System.out.println("YES");
 else System.out.println("NO");

//System.out.println(totalTime+" sec....."+" "+startTime+" "+endTime);

}public static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;

public InputReader(InputStream stream)
{
this.stream = stream;
}

public 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++];
}

public 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;
}

public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
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;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}

public String next()
{
return readString();
}

public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long friends = in.nextLong();

        if (friends == 0) {
            System.out.println(0);
        }

        if (friends % 2 == 0) {
            System.out.println(friends + 1);
        } else if {
            System.out.println((friends + 1) / 2);
        }
    }
}


import java.io.*;
import java.util.*;
public class Pizza
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();

        if(n%2==0)
        System.out.println(n+1);
        else
        System.out.println((n+1)/2));
    }
}


import java.util.Scanner;

public class Test {

  private static final Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {
   long people = scanner.nextLong();
   if (people = 0) {
     System.out.println("0");
   } else if (people%2 != 0) {
     System.out.println((people+1)/2);
   } else if (people%2 == 0){
     System.out.println(people+1);
   }
  }
}


import java.io.*;
import java.util.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static final double EPS = 1e-9;
	static long mod = 1000000007;
	static int inf = 1000000000;
	static long[] fac;
	static int[] si;
	static ArrayList<Integer> primes;
	static int n,m;
	static ArrayList<Integer>[] adjList, tree;
	static Stack<Integer> stack;
	static int[] dfs_low, dfs_num, bridgeComp;
	static int V, counter,count;
    static int chosen;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
	    long x=sc.nextLong();
	    long y=sc.nextLong();
	    long l=sc.nextLong();
	    long r=sc.nextLong();
	    TreeSet<Long> in=new TreeSet<>();
	    long limitx=(long)((double)Math.log10(10e18)/(double)Math.log10(x));
	    long limity=(long)((double)Math.log10(10e18)/(double)Math.log10(y));
	    for(int i=0;i<=limity;i++) {
	    	for(int j=0;j<=limitx;j++) {
	    		long h=power(x,j)+power(y,i);
	    		if(h>=l && h<=r)
	    			in.add(h);
	    	}
	    }
	    long ans=0;
	    long last=l;
	    for(long h:in) {
	    	ans=Math.max(ans, h-last-1);
	    	last=h;
	    }
	    if(!in.contains(r))
	    ans=Math.max(ans, r-last);
	    if(!in.contains(l))
		    ans=Math.max(ans, in.first()-l);
	   // System.out.println(in);
	    out.println(ans);
		out.flush();
	}
	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;
	}
	static int []dist;
	static void bfs(int s) {
		dist[s]=0;
		Queue <Integer> q=new LinkedList();
		q.add(s);
		while(!q.isEmpty()) {
			int u=q.poll();
			for(int v:tree[u]) {
				if(dist[v]==-1) {
					dist[v]=1+dist[u];
					q.add(v);
				}
			}
		}
	}
	static void bridgeTree()
	{
		counter = 0;
		dfs_low = new int[V];
		dfs_num = new int[V];
		bridgeComp = new int[V];
		stack = new Stack<Integer>();
		tree = new ArrayList[V];
		for(int i = 0; i < V; ++i)
			tree[i] = new ArrayList<Integer>();
		for(int i = 0; i < V; ++i)
			if(dfs_num[i] == 0)
				dfs(i, -1);
		for(int u = 0; u < V; ++u)
			for(int v: adjList[u])
			{
				int x = bridgeComp[u], y = bridgeComp[v];
				if(x != y)
					tree[x].add(y);
			}
	}
	static void dfs(int u, int p)
	{
		dfs_num[u] = dfs_low[u] = ++counter;
		stack.push(u);
		for(int v: adjList[u])
			if(v != p)
				if(dfs_num[v] == 0)
				{
					dfs(v, u);
					dfs_low[u] = Math.min(dfs_low[u], dfs_low[v]);
					if(dfs_low[v] > dfs_num[u])
						extract(v);
				}
				else
					dfs_low[u] = Math.min(dfs_low[u], dfs_num[v]);
		if(p == -1)
			extract(u);
	}
	static void extract(int u)
	{
		while(true)
		{
			int v = stack.pop();
			bridgeComp[v] = u;
			if(v == u)
				break;
		}
	}
	static void seive() {
		 si=new int [1000001];
		    primes=new ArrayList<>();
		    int N=1000001;
		    si[1]=1;
		    for(int i=2;i<N;i++) {
		    	if(si[i]==0) {
		    		si[i]=i;
		    		primes.add(i);
		    	}
		    	for(int j=0;j<primes.size() && primes.get(j)<=si[i] && (i*primes.get(j))<N;j++)
		    		si[primes.get(j)*i]=primes.get(j);

		    }
	}
	static class pair implements Comparable<pair> {
		long x;
		long y;

		pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

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

		public int compareTo(pair o) {
			return (int)((o.x-o.y)-(x-y));
		}
	}

	static long inver(long x) {
		int a = (int) x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				// System.out.println(res*a);
				res = (int) ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		// out.println(res+" "+x);
		return res % mod;
	}

	static long fac(int n) {
		if (n == 0)
			return fac[n] = 1;
		if (n == 1)
			return fac[n] = 1;
		long ans = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = ans = (i % mod * ans % mod) % mod;
		return ans % mod;
	}

	static long gcd(long a, long b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

public class B{
    public static void main (String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        TreeSet<Long> list = new TreeSet<>();
        long x = fs.nextLong(), y = fs.nextLong();
        long l = fs.nextLong(), r = fs.nextLong();

        BigInteger uLim = BigInteger.valueOf(r);
        BigInteger lLim = BigInteger.valueOf(l);

        for(int i = 0; i <= 63; i++) {
            for(int j = 0; j <= 63; j++) {
                BigInteger p1 = BigInteger.valueOf(x).pow(i);
//                if(j == 1 && i == 0) System.out.println(p1);
                if(p1.compareTo(uLim) > 0) continue;
                p1 = p1.add(BigInteger.valueOf(y).pow(j));
                if(p1.compareTo(uLim) > 0) continue;
                if(p1.compareTo(lLim) < 0) continue;

                list.add(p1.longValue());

            }
        }

//        System.out.println(list);

        ArrayList<Long> loop = new ArrayList<>(list);
        long max = 0;
        for(int i = 1; i < loop.size(); i++) {
            long one = loop.get(i), two = loop.get(i-1);
            long dist = one - two - 1;
            max = Math.max(max, dist);
        }
        max = Math.max(max, list.first() - l);
        max = Math.max(max, r - list.last());

        System.out.println(max);

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
//                br = new BufferedReader(new FileReader("testdata.out"));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

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

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

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }
}


import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;

 public class Main {
	private InputStream is;
	private PrintWriter out;
	int time = 0, dp[][], DP[][], start[], end[], val[], black[], MOD = (int)(1e9+7), arr[], arr1[];
	int MAX = 10000000, N, K, p;
	ArrayList<Integer>[] amp, amp1;
	boolean b[], b1[];
	Pair prr[];
	char ch[][];
	HashSet<Integer> hs = new HashSet<>();

	public static void main(String[] args) throws Exception {
		new Thread(null, new Runnable() {
		public void run() {
			try {

		//new Main().soln();
		} catch (Exception e) {
				System.out.println(e);
			}
		}
	}, "1", 1 << 26).start();
		new Main().soln();
	}
	void solve() {
		long x = nl(), y = nl(), l = nl(), r = nl();
		long temp = 1;
		ArrayList<Long> amp1 = new ArrayList<>();
		ArrayList<Long> amp2 = new ArrayList<>();
		amp1.add(temp);
		amp1.add(0L);
		while(r/temp>=x){
			temp *= x;
			amp1.add(temp);
		}
		temp = 1;
		amp2.add(temp);
		amp2.add(0L);
		while(r/temp>=y){
			temp *= y;
			amp2.add(temp);
		}
	//	System.out.println(amp1+" "+amp2);
		ArrayList<Long> fa = new ArrayList<>();
		for(int i = 0; i< amp1.size(); i ++){
			for(int j = 0;j<amp2.size();j++){
				long aa = amp1.get(i)+amp2.get(j);
				if(aa>=l && aa<=r)
				fa.add(aa);
			}
		}
		Collections.sort(fa);
		long max = fa.get(0)-l;
		long left = fa.get(0);
		for(int i = 0; i< fa.size();i++){
			max = Math.max(max, fa.get(i)-left-1);
			left = fa.get(i);
		}
		//System.out.println(fa);
		max = Math.max(r-fa.get(fa.size()-1), max);
		System.out.println(max);
	}

	int calc(int[] c, int[] d, int n, int m, int e){
		int ans = 0;
		for(int i = 0;i<n;i++){
			for(int j = 0;j<m ;j++){
				if(Math.abs(c[i]-d[j])<=e) ans++;
			}
		}
		return ans;
	}
	int binarySearch(int arr[], int key){
		int low = 0, high = arr.length-1;
		int ans = high;
		if(key>arr[high]){
			return -high-2;
		}
		while(high>=low){
			int mid = (low+high)/2;
			if(arr[mid]>=key){
				high = mid-1;
				ans = mid;
			}
			else low = mid+1;
		}
		if(arr[ans]!=key) return (-ans-1);
		return ans;
	}
	int min(int x,int y){
		if(x<y) return x;
		return y;
	}
	int max(int x,int y){
		if(x>y) return x;
		return y;
	}
	void dfs(int x){
		b[x] = true;
		for(int i : amp[x]){
			if(!b[i]){
				dfs(i);
			}
		}
	}
	void buildGraph(int m){
		while(m-->0)
		{
			int x = ni(), y = ni();
			amp[--x].add(--y);
		}
	}
	long modInverse(long a, long mOD2){
        return  power(a, mOD2-2, mOD2);
	}
	long power(long x, long y, long m)
	{
		if (y == 0)
    return 1;
	long p = power(x, y/2, m) % m;
	p = (p * p) % m;

	return (y%2 == 0)? p : (x * p) % m;
	}
	boolean isPrime(int x){
		for(int i = 2;i*1L*i<=x;i++) if(x%i==0) return false;
		return true;
	}
	public long gcd(long a, long b){
		if(b==0) return a;
		return gcd(b,a%b);
	}
	void failFn(String str, int arr[]){
		int len = 0;
		arr[0] = 0;
		int i = 1;
		while(i<arr.length){
			if(str.charAt(i)==str.charAt(len)){
				arr[i++] = ++len;
				continue;
			}
			if(len == 0){
				arr[i] = len;
				i++;
				continue;
			}
			if(str.charAt(i)!=str.charAt(len)){
				len = arr[len-1];
			}
		}
	}
	static class ST1{
		int arr[], st[], size;
		ST1(int a[]){
			arr = a.clone();
			size = 10*arr.length;
			st = new int[size];
			build(0,arr.length-1,1);
		}
		void build(int ss, int se, int si){
			if(ss==se){
				st[si] = arr[ss];
				return;
			}
			int mid = (ss+se)/2;
			int val = 2*si;
			build(ss,mid,val); build(mid+1,se,val+1);
			st[si] = (st[val]+ st[val+1]);
		}
		int get(int ss, int se, int l, int r, int si){
			if(l>se || r<ss || l>r) return Integer.MAX_VALUE;
			if(l<=ss && r>=se) return st[si];
			int mid = (ss+se)/2;
			int val = 2*si;
			return (get(ss,mid,l,r,val)+ get(mid+1,se,l,r,val+1));
		}
	}
	static class ST{
		int arr[],lazy[],n;
		ST(int a){
			n = a;
			arr = new int[10*n];
			lazy = new int[10*n];
		}
		void up(int l,int r,int val){
			update(0,n-1,0,l,r,val);
		}
		void update(int l,int r,int c,int x,int y,int val){
			if(lazy[c]!=0){
				lazy[2*c+1]+=lazy[c];
				lazy[2*c+2]+=lazy[c];
				if(l==r)
					arr[c]+=lazy[c];
				lazy[c] = 0;
			}
			if(l>r||x>y||l>y||x>r)
				return;
			if(x<=l&&y>=r){
				lazy[c]+=val;
				return ;
			}
			int mid = l+r>>1;
			update(l,mid,2*c+1,x,y,val);
			update(mid+1,r,2*c+2,x,y,val);
			arr[c] = (arr[2*c+1]+ arr[2*c+2]);
		}
		int an(int ind){
			return ans(0,n-1,0,ind);
		}
		int ans(int l,int r,int c,int ind){
			if(lazy[c]!=0){
				lazy[2*c+1]+=lazy[c];
				lazy[2*c+2]+=lazy[c];
				if(l==r)
					arr[c]+=lazy[c];
				lazy[c] = 0;
			}
			if(l==r)
				return arr[c];
			int mid = l+r>>1;
			if(mid>=ind)
				return ans(l,mid,2*c+1,ind);
			return ans(mid+1,r,2*c+2,ind);
		}
	}
	public static class FenwickTree {

	    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates

	    public FenwickTree(int size) {
	        array = new int[size + 1];
	    }
	    public int rsq(int ind) {
	        assert ind > 0;
	        int sum = 0;
	        while (ind > 0) {
	            sum += array[ind];
	            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
	            ind -= ind & (-ind);
	        }
	        return sum;
	    }
	    public int rsq(int a, int b) {
	        assert b >= a && a > 0 && b > 0;
	        return rsq(b) - rsq(a - 1);
	    }
	    public void update(int ind, int value) {
	        assert ind > 0;
	        while (ind < array.length) {
	            array[ind] += value;
	            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
	            ind += ind & (-ind);
	        }
	    }
	    public int size() {
	        return array.length - 1;
	    }
	}
	public static int[] shuffle(int[] a, Random gen){
		for(int i = 0, n = a.length;i < n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int d = a[i];
			a[i] = a[ind];
			a[ind] = d;
		}
	return a;
	}

	class Pair implements Comparable<Pair>{
		int u, v;
		Pair(int u, int v){
			this.u = u;
			this.v = v;
		}public int hashCode() {
			return Objects.hash();
		}
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return ((u == other.u && v == other.v));// || (v == other.u && u == other.v));
		}
		public int compareTo(Pair other) {
			//return Integer.compare(val, other.val);
			return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(other.v,v));
		}
		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	long power(long x, long y, int mod){
		long ans = 1;
		while(y>0){
			if(y%2==0){
				x = (x*x)%mod;
				y/=2;
			}
			else{
				ans = (x*ans)%mod;
				y--;
			}
		}
		return ans;
	}
	void soln() {
		is = System.in;
		out = new PrintWriter(System.out);
		long s = System.currentTimeMillis();
		solve();
		//out.close();
		out.flush();
		//tr(System.currentTimeMillis() - s + "ms");
	}

	// To Get Input
	// Some Buffer Methods
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

public class SolutionB {

	public static void main(String[] args) {
		new SolutionB().run();
	}
	int n, m;
	int c[], d[];
	void solve() {
		n = in.nextInt();
		m = in.nextInt();
		c = in.nextIntArray(n);
		d = in.nextIntArray(n);
		Matrix st = new Matrix(50);
		for(int i = 0; i < n; i++){
			Matrix fi = new Matrix(50);
			for(int j = 0; j<50; j++)
				fi.a[j][j] = Integer.MAX_VALUE/2;
			for(int j = 0; j<49; j++){
				fi.a[j+1][j] = d[i];
				fi.a[j][j+1] = c[i];
			}
			st = st.mul(fi);
		}
		out.println(st.pow(m).a[0][0]);
	}

	class Matrix{
		int n;
		int a[][];
		public Matrix(){
			a = new int[2][2];
		}
		public Matrix(int n){
			this.n = n;
			a=new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j=0; j < n; j++){
					if(i == j) a[i][j] = 0;
					else a[i][j] = Integer.MAX_VALUE/2;
				}
			}
		}
		Matrix mul(Matrix x){
			Matrix t = new Matrix(n);
			for(int i = 0; i < n; i++)
				for(int j = 0;j < n; j++){
					t.a[i][j] = Integer.MAX_VALUE/2;
					for(int k = 0; k < n; k++){
						t.a[i][j] = Math.min(t.a[i][j], a[i][k] + x.a[k][j]);
					}
				}
			return t;
		}
		Matrix pow(int x){

			if(x == 0) {
				Matrix t = new Matrix(n);
				return t;
			}
			if(x % 2 == 0){
				return this.mul(this).pow(x/2);
			}
			return this.mul(this.pow(x-1));
		}
	}

	class Pair implements Comparable<Pair> {
		int x, y;

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

		@Override
		public int compareTo(Pair o) {
			if (o.x == x)
				return ((Integer) y).compareTo(o.y);
			return ((Integer) x).compareTo(o.x);
		}

	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner(System.in);
		out = new PrintWriter(new OutputStreamWriter(System.out));
		solve();
		out.close();
	}

	void runIO() {
		try {
			in = new FastScanner(new File("expr.in"));
			out = new PrintWriter(new FileWriter(new File("expr.out")));
			solve();
			out.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader bf;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				bf = new BufferedReader(new FileReader(f));
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

		public FastScanner(InputStream is) {
			bf = new BufferedReader(new InputStreamReader(is), 32768);
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(bf.readLine());
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

		String nextLine() {
			try {
				return bf.readLine();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			return "";
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(next());
		}

		BigDecimal nextBigDecimal() {
			return new BigDecimal(next());
		}

		int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = Integer.parseInt(next());
			return a;
		}

		long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = Long.parseLong(next());
			return a;
		}
	}
}


import java.io.*;
import java.util.Arrays;

public class CF351C
{
    public static int[] a = null;
    public static int[] b = null;
    public static int n = 0;
    public static int m = 0;

    public static int[] intArray(String s)
    {
        String[] splits = s.trim().split(" +");
        int[] array = new int[splits.length];
        for (int i = 0; i < array.length; i++)
            array[i] = Integer.parseInt(splits[i]);
        return array;
    }

    public static int calcInkRequired(Boolean[] brackets)
    {
        int inkRequired = 0;
        for (int i = 0; i < n; i++)
        {
            if (brackets[i].booleanValue())
                inkRequired += b[i];
            else
                inkRequired += a[i];
        }
        return inkRequired;
    }

    public static void widen()
    {
        int[] _a = Arrays.copyOf(a, n * 2);
        for (int i = 0; i < n; i++)
            _a[i + n] = _a[i];
        a = _a;
        int[] _b = Arrays.copyOf(b, n * 2);
        for (int i = 0; i < n; i++)
            _b[i + n] = _b[i];
        b = _b;
        n *= 2;
        m /= 2;
        return;
    }

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] _nm = intArray(br.readLine());
        n = _nm[0];
        m = _nm[1];
        a = intArray(br.readLine());
        b = intArray(br.readLine());

        if ((n % 2) == 1)
            widen();

        int bestBestInkRequired = 0;
        if (n > 0)
        {
            while (true)
            {
                int halfN = n / 2;
                // false = open, true = close
                Boolean[] brackets = new Boolean[n];
                int level = 0;
                int[] sizes = new int[halfN];
                int[] indexes = new int[halfN];
                int bestInkRequired = 0;
levelLoop:
                while (level >= 0)
                {
                    int curSize = sizes[level];
                    int curIndex = indexes[level];
                    if (curSize == 0)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (brackets[i] == null)
                            {
                                indexes[level] = i;
                                curIndex = i;
                                break;
                            }
                        }
                        sizes[level] = 2;
                    }
                    else
                    {
                        brackets[curIndex] = null;
                        brackets[curIndex + curSize - 1] = null;
                        sizes[level] += 2;
                    }
                    curSize = sizes[level];
                    if ((curIndex + curSize) > n)
                    {
                        level--;
                        continue levelLoop;
                    }
                    for (int i = 0; i < curSize; i++)
                    {
                        if (brackets[curIndex + i] != null)
                        {
                            level--;
                            continue levelLoop;
                        }
                    }
                    brackets[curIndex] = Boolean.FALSE;
                    brackets[curIndex + curSize - 1] = Boolean.TRUE;
                    level++;
                    if (level < halfN)
                        sizes[level] = 0;
                    else
                    {
                        int inkRequired = calcInkRequired(brackets);
                        if ((bestInkRequired == 0) || (inkRequired < bestInkRequired))
                            bestInkRequired = inkRequired;
                        level--;
                    }
                }

                if ((bestBestInkRequired == 0) || (bestInkRequired < bestBestInkRequired))
                {
                    bestBestInkRequired = bestInkRequired;
                    if ((m % 2) == 1)
                        break;
                    // Retry with wider scope
                    widen();
                }
                else
                {
                    n /= 2;
                    m *= 2;
                    break;
                }
            }
        }
        System.out.println(String.valueOf(bestBestInkRequired * m));
        return;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class R204C {
    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    int INF = Integer.MAX_VALUE/3;
    public void solve() throws IOException {
      int N = nextInt();
      int M = nextInt();
      int[] A = new int[N];
      int[] B = new int[N];
      for (int i = 0; i < N; i++)
        A[i] = nextInt();
      for (int i = 0; i < N; i++)
        B[i] = nextInt();

      int[][][] dp = new int[N+1][2*N+1][2*N+1];
      for(int i = 0; i <= N; i++){
        for(int j = 0; j <= 2*N; j++){
          Arrays.fill(dp[i][j], INF);
        }
      }
      for(int i = 0; i <= 2*N; i++){
        dp[0][i][i] = 0;
      }

      for(int i = 0; i < N; i++){
        for(int j = 0; j <= 2*N; j++){
          for(int k = 0; k <= 2*N; k++){
            if (dp[i][j][k] == INF) continue;

            if(k < 2*N)
              dp[i+1][j][k+1] = Math.min(dp[i+1][j][k+1], dp[i][j][k] + A[i]);

            if(k > 0)
              dp[i+1][j][k-1] = Math.min(dp[i+1][j][k-1], dp[i][j][k] + B[i]);
          }
        }
      }

      int[][] T = new int[2*N+1][2*N+1];
      for(int i = 0; i <= 2*N; i++){
        for(int j = 0; j <= 2*N; j++){
          T[i][j] = dp[N][i][j];
        }
      }
      int[][] TT = pow(T, M);

//      for(int i = 0; i <= 2*N; i++){
//        for(int j = 0; j <= 2*N; j++){
//          out.print(T[i][j] + " ");
//        }
//        out.println();
//      }
      out.println(TT[0][0]);
    }

    public int[][] pow(int[][] A, int N){
      if (N == 1){
        int[][] ret = A.clone();
        return ret;
      }

      if (N % 2 == 1)
        return mul(A, pow(A, N-1));
      else
        return pow(mul(A, A), N/2);
    }

    public int[][] mul(int[][] A, int[][] B){
      int[][] ret = new int[A.length][A[0].length];
      for(int i = 0; i < A.length; i++){
        Arrays.fill(ret[i], INF);
      }

      for(int k = 0; k < A.length; k++){
        for(int i = 0; i < A.length; i++){
          for(int j = 0; j < A.length; j++){
            if (A[i][k] == INF || B[k][j] == INF) continue;
            ret[i][j] = Math.min(ret[i][j], A[i][k] + B[k][j]);
          }
        }
      }
      return ret;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        new R204C().run();
    }

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class R3_D2_D {
    static ArrayList<Integer>[] edge;
    static ArrayList<Integer>[] revEdge;
    static boolean vis1[];
    static boolean vis2[];

    public static void dfs1(int index) {
        if (!vis1[index]) {
            vis1[index] = true;
            for (int a : edge[index])
                dfs1(a);
        }
    }

    public static void dfs2(int index) {
        if (!vis2[index]) {
            vis2[index] = true;
            for (int a : revEdge[index])
                dfs2(a);
        }
    }

    public static void main(String[] args) {
        // BufferedReader in = new BufferedReader(new
        // InputStreamReader(System.in));

        InputReader in = new InputReader(System.in);
        int n = in.readInt();
        int m = in.readInt();
        vis1 = new boolean[n];
        vis2 = new boolean[n];
        int[] inp = new int[n];
        for (int i = 0; i < inp.length; i++) {
            inp[i] = in.readInt();
        }
        edge = new ArrayList[n];
        revEdge = new ArrayList[n];
        for (int j = 0; j < inp.length; j++) {
            edge[j] = new ArrayList<Integer>();
            revEdge[j] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int a = in.readInt() - 1;
            int b = in.readInt() - 1;
            edge[a].add(b);
            revEdge[b].add(a);
        }
        for (int i = 0; i < inp.length; i++) {
            if (inp[i] == 1)
                dfs1(i);
        }
        for (int i = 0; i < inp.length; i++) {
            if (inp[i] == 2)
                dfs2(i);
        }
        for (int i = 0; i < inp.length; i++) {
            if(vis1[i] && vis2[i])
                System.out.println(1);
            else
                System.out.println(0);
        }
    }

    public static class tr {
        int x;
        int y;
        int z;

        public tr(int a, int b, int c) {
            x = a;
            y = b;
            z = c;
        }
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1000];
        private int curChar, numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private 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++];
        }

        public int readInt() {
            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;
        }

        public long readLong() {
            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;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines)
                return readLine();
            else
                return readLine0();
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;

public class VKRound3A {
    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer st = new StringTokenizer("");
    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    static String next() throws Exception {
        while (true) {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            st = new StringTokenizer(s);
        }
    }
    static int n, m;
    static int state [];
    static ArrayList<Integer> graph [];
    static boolean vis [];
    static ArrayList<Integer> curpath = new ArrayList<Integer>();
    static HashSet<Integer> important = new HashSet<Integer>();
    public static void dfs(int idx){
        if(state[idx] == 2){
            important.add(idx);
            for(int i = curpath.size() - 1 ; i >= 0 ; --i){
                if(state[curpath.get(i)] == 1){
                    important.add(curpath.get(i));
                    break;
                }else{
                    important.add(curpath.get(i));
                }
            }
            vis[idx] = true;
            return;
        }
        if(vis[idx])
            return;
        vis[idx] = true;
        curpath.add(idx);
        for(int i = 0 ; i < graph[idx].size() ; ++i){
            int nxt = graph[idx].get(i);
                dfs(nxt);
        }
        curpath.remove((Integer) idx);
    }
    @SuppressWarnings("unchecked")
    public static void main(String[] args)throws Exception {
        n = nextInt();
        m = nextInt();
        state = new int [n + 1];
        vis = new boolean [n + 1];
        graph = new ArrayList [n + 1];
        for(int i = 0 ; i < n + 1 ; ++i)
            graph[i] = new ArrayList<Integer>();
        for(int i = 1 ; i < n + 1 ; ++i)
            state[i] = nextInt();
        for(int i = 0 ; i < m ; ++i){
            int a = nextInt();
            int b = nextInt();
            graph[a].add(b);
        }
        for(int i = 1 ; i < n + 1 ; ++i){
            if(!vis[i] && state[i] == 1)
                dfs(i);
        }
        for(int i = 1 ; i < n + 1 ; ++i)
            if(important.contains(i))
                System.out.println(1);
            else
                System.out.println(0);
    }
}


import java.util.*;

public class ChatRoom {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner(System.in);
        String stg = in.next();

        String hello = "hello";
        int count = 0;
        for (int i = 0; i < stg.length();) {
            for (int j = 0; j < hello.length(); j++) {
                if (stg.charAt(i) == hello.charAt(j)) {
                    count++;
                }
            }

        }
        if (count >= 5) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}


import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ProblemE {
    public static int w, h;

    public static int MAX = 9999999;

    public static Set<Integer> result = new HashSet<Integer>();

    public static void dfs(int n, int m, int mask) {
        if (n >= w) {
            result.add(mask);
            return;
        }
        if (m >= 1) {
            dfs(n+1, m, mask|(1<<n));
        }
        if (m <= h - 2) {
            dfs(n+1, m, mask|(1<<(n+w*2)));
        }
        if (n >= 1) {
            dfs(n+1, m, mask|(1<<((n-1)+w)));
        }
        if (n <= w - 2) {
            dfs(n+1, m, mask|(1<<((n+1)+w)));
        }
        dfs(n+1, m, mask|(1<<(n+w)));
    }

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String[] line = s.nextLine().split(" ");
        w = Integer.valueOf(line[0]);
        h = Integer.valueOf(line[1]);
        if (w > h) {
            int tmp = w;
            w = h;
            h = tmp;
        }

        int[][] dp = new int[h+1][1<<(w*3)];
        for (int i = 0 ; i <= h ; i++) {
            for (int j = 0 ; j < 1<<(w*3) ; j++) {
                dp[i][j] = MAX;
            }
        }
        dp[0][0] = 0;

        for (int i = 0 ; i < h ; i++) {
            result.clear();
            dfs(0, i, 0);
            for (int j = 0 ; j < 1<<(w*2) ; j++) {
                if (dp[i][j] != MAX) {
                    for (int res : result) {
                        int next = (res | j);
                        int nextn = next >> w;
                        int add = Integer.bitCount(next & ((1<<w) - 1));
                        dp[i+1][nextn] = Math.min(dp[i+1][nextn], dp[i][j] + add);
                    }
                }
            }
        }

        int answer = MAX;
        for (int j = 0 ; j < 1<<(w*2) ; j++) {
            answer = Math.min(answer, dp[h][j] + Integer.bitCount(j));
        }
        System.out.println(h * w - answer);
    }
}


//package round85;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class C2 {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int m = ni();
		boolean[][] f = new boolean[99][99];
		cache = new HashSet<Long>();
		out.println(n*m-rec(f, n, m, 0, 0, 0));
	}

	Set<Long> cache;

	long hash(boolean[][] f, int n, int m, int r, int c, int cur)
	{
		long x = 0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(f[i][j])x |= 1L<<i*m+j;
			}
		}
		x = x * n + r;
		x = x * m + c;
		x = x * 41 + cur;
		return x;
	}

	int rec(boolean[][] f, int n, int m, int r, int c, int cur)
	{
		if(r == n)return cur;
		if(c >= m)return rec(f, n, m, r+1, 0, cur);
		long h = hash(f, n, m, r, c, cur);
		if(cache.contains(h))return 99999;
		cache.add(h);
		int min = f[r][c] ? rec(f, n, m, r, c+1, cur) : 99999;
		{
			boolean[] memo = new boolean[]{f[r][c], f[r+1][c], f[r+2][c], f[r+1][c+1], c-1>=0 ? f[r+1][c-1] : false};
			f[r][c] = true;
			f[r+1][c] = true;
			f[r+2][c] = true;
			f[r+1][c+1] = true;
			if(c-1 >= 0)f[r+1][c-1] = true;
			min = Math.min(min, rec(f, n, m, r, c+1, cur+1));
			f[r][c] = memo[0];
			f[r+1][c] = memo[1];
			f[r+2][c] = memo[2];
			f[r+1][c+1] = memo[3];
			if(c-1 >= 0)f[r+1][c-1] = memo[4];
		}
		{
			boolean[] memo = new boolean[]{f[r][c], f[r][c+1], f[r][c+2], f[r+1][c+1]};
			f[r][c] = true;
			f[r][c+1] = true;
			f[r][c+2] = true;
			f[r+1][c+1] = true;
			min = Math.min(min, rec(f, n, m, r, c+3, cur+1));
			f[r][c] = memo[0];
			f[r][c+1] = memo[1];
			f[r][c+2] = memo[2];
			f[r+1][c+1] = memo[3];
		}
		return min;
	}

	int count(int n, int m, int p, int step)
	{
		int[] dr = {1, 0, -1, 0, 0};
		int[] dc = {0, 1, 0, -1, 0};

		// (0,i)
		int ct = 0;
		boolean[][] f = new boolean[n][m];
		for(int j = 0;j < n;j++){
			for(int k = 0;k < m;k++){
				if(k % 5 == p){
					ct++;
					for(int l = 0;l < 5;l++){
						int nr = j+dr[l];
						int nc = k+dc[l];
						if(nr >= 0 && nr < n && nc >= 0 && nc < m){
							f[nr][nc] = true;
						}
					}
				}
			}
			p = (p+step)%5;
		}

		for(int j = 0;j < n;j++){
			for(int k = 0;k < m;k++){
				if(!f[j][k]){
					ct++;
					for(int l = 0;l < 5;l++){
						int nr = j+dr[l];
						int nc = k+dc[l];
						if(nr >= 0 && nr < n && nc >= 0 && nc < m){
							f[nr][nc] = true;
						}
					}
				}
			}
		}
		return ct;
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new C2().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


package com;

import java.io.InputStreamReader;
import java.util.Scanner;

public class A {

	public static void main(String[] args){
		String n;
		String line;
		Scanner scanner = new Scanner(new InputStreamReader(System.in));

		line = scanner.nextLine();

		scanner.close();

		if((Integer.valueOf(line))%2 == 0) {
			System.out.println("Mahmoud");
		} else {
			System.out.println("Ehab");
		}

	}

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Adly
 */
public class BIGBRAIN {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tmp1=in.nextInt();
        if(in.nextInt()==1){
            System.out.println("Ehab");
        }else{
            System.out.println("Mahmoud");
        }
    }
}


package math.codeforces;

import java.util.Scanner;

public class AddOrSubtractOddEven {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long T = s.nextLong();
		if(T%2==0){
		    System.out.println("Mahmoud");
		}else{
		    System.out.println("Ehab");
		}
		s.close();
	}

}


package codeforces;

import java.io.*;
import java.util.*;
public class problemA {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.valueOf(br.readLine());
		if(n%2 == 0) {
			System.out.println("Mahmoud");
		} else {
			System.out.println("Ehab");
		}
	}

}


import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
public class CF429B {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		String string = scan.next();
		int len = string.length();
		Map<Character, Integer> numChars = new HashMap<Character, Integer>(Math.min(len, 26));

		for (int i = 0; i < len; ++i)
		{
		    char charAt = string.charAt(i);

		    if (!numChars.containsKey(charAt))
		    {
		        numChars.put(charAt, 1);
		    }
		    else
		    {
		        numChars.put(charAt, numChars.get(charAt) + 1);
		    }
		} if (len % y == 0){
			System.out.println("YES");
		} else{
			System.out.println("NO");
		}

	}
}


import java.util.Scanner;

public class OddsAndEnds {
    static int [] arr;
    static boolean done = false;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int len = scan.nextInt();
        arr = new int[len];
        for (int i = 0; i < len; i++) {
            arr[i] = scan.nextInt();
        }
        partition(new int[len], len, len, 0);
        if (done) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
        scan.close();
    }

    private static void checkAnswer(int[] p, int n) {
        int begin = 0;
        for (int i = 0; i < n; i++) {
            if (arr[begin] % 2 == 0) {
                return;
            }
            if (arr[begin + p[i] - 1] % 2 == 0) {
                return;
            }
            begin += p[i];
        }

        done = true;
    }

    private static void partition(int[] p, int n, int m, int i) {
        if (n == 0) {
            if (i % 2 != 0) {
                checkAnswer(p, i);
            }
        }
        else {
            for (int k = m; k > 0; k--) {
                if (done) {
                    return;
                }

                if (k % 2 != 0) {
                    p[i] = k;
                    partition(p, n - k, n - k, i + 1);
                }
            }
        }
    }

}


//package semanai;
import java.util.Scanner;

public class OddsEnds {

    public static void oddsEnds(){
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();

        int phase =1;

        int previous = 0;
        boolean still_valid= true;

        for (int i =0; i<size; i++){
            int current = sc.nextInt();
            if ((current>previous)&&(phase==1)){
                previous = current;

            }else if ((current==previous)&&(phase==1)){
                previous = current;
                phase=2;

            }else if ((current<previous)&&(phase==1)){
                previous = current;
                phase=3;

            }else if ((current>previous)&&(phase==2)){
                still_valid=false;
                break;

            }else if ((current==previous)&&(phase==2)){
                previous = current;

            }else if ((current<previous)&&(phase==2)){
                previous = current;
                phase=3;

            }else if ((current>previous)&&(phase==3)){
                still_valid=false;
                break;

            }else if ((current==previous)&&(phase==3)){
                still_valid=false;
                break;

            }else if ((current<previous)&&(phase==3)){
                previous = current;

            }

        }
        sc.close();

        if(still_valid){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

    public static void main(String[] args) {
        oddsEnds();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nguyen Trung Hieu - vuondenthanhcong11@yahoo.com
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    int answer = 0;
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int count = in.readInt();
        dfs(0, count);
        out.printLine(answer);
    }

    private void dfs(long x, int count) {
        if (x > 0 && x <= count)
            answer++;
        if (x > count)
            return;
        for (int i = 0; i < 10; i++) {
            if (10 * x + i > 0 && haveTwoDigit(10 * x + i))
                dfs(10 * x + i, count);
        }
    }

    private boolean haveTwoDigit(long x) {
        int[] numberDigit = new int[10];
        int cnt = 0;
        while (x > 0) {
            numberDigit[(int)x % 10]++;
            x /= 10;
        }
        for (int i = 0; i < 10; i++)
            if (numberDigit[i] > 0)
                cnt++;
        return (cnt <= 2);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public 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++];
    }

    public int readInt() {
        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;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }

    }

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Round150_B {

    static HashSet<Integer> hash = new HashSet<Integer>();
    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader();

        int N = in.nextInt();
        String s = N + "";
        int len = s.length();
        int c = 0;

        while (len > 0) {
            for (int first = 0; first < 10; first++)
                for (int second = first + 1; second < 10; second++) {
                    if (first == second)
                        continue;

                    for (int i = 0; i < (1 << len); i++) {
                        StringBuffer res = new StringBuffer("");
                        for (int j = 0; j < len; j++)
                            if ((i & (1 << j)) != 0)
                                res.append(first + "");
                            else
                                res.append(second + "");
                        int z = Integer.parseInt(res.toString());
                        if (z <= N && (z + "").length() == len && !hash.contains(z)) {
                            hash.add(z);
                            c++;
                        }

                    }
                }
            len--;
            if(len == 0)break;
            StringBuffer q = new StringBuffer("");
            for (int i = 0; i < len; i++)
                q.append(9);
            N = Integer.parseInt(q.toString());
        }
        System.out.println(c-1);

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer st;

        public InputReader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer(in.readLine());

        }

        public String next() throws IOException {

            while (!st.hasMoreElements())
                st = new StringTokenizer(in.readLine());
            return st.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String ch = "hello";
        boolean w = true;
        int i = 0, j = 0;
        while(w && i < s.length())
        {
            if(s.charAt(i) == 'h')
            {
                if( s.charAt(i) != ch.charAt(j) )
                {
                    if( s.charAt(i) == ch.charAt(j + 1))
                    {
                      j++;

                    }
                    else{
                        w = false;
                    }

                }
            }
            else{
                i++;
            }
        }
        System.out.println(w ? "YES" : "NO");
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class A {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
//        int T = fs.nextInt();

//        for (int tt = 0; tt < T; tt++) {
        String s = fs.nextLine();
        String h = "hello";
        int j =4;
        for(int i=s.length()-1;i>=0;i--){
            if(j>-1&&s.charAt(i)==h.charAt(j)){
                System.out.println(h.charAt(j)+" "+j);
                j--;
            }

        }

        if(j==-1)
            System.out.println("YES");
        else
            System.out.println("NO");

//    }

    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        Integer[] readArray(int n) {
            Integer[] a=new Integer[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine(){
            return  String.valueOf(next());
        }

    }

}


package first_contest_37;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class slime {

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		int input =Integer.parseInt(bf.readLine());
		ArrayList<Integer> results=new ArrayList<Integer>();
		results.add(1);
		for (int i = 1; i < input; i++) {
			int last=results.get(results.size()-1);
			//System.out.println("size of the array is "+results.size());
			//System.out.println("last is "+last);
			if(last==1){
				results.remove(results.size()-1);
				results.add(2);
				combine(results);
			}
			else{
				results.add(1);
			}
		}
		String R="";
		for (int i = 0; i < results.size(); i++) {
			R+=results.get(i)+" ";
		}
		System.out.println(R);
		}
	public static void combine(ArrayList<Integer>results){
		for (int i = results.size()-1; i>0; i--) {
			//System.out.println("you have called combine");
			if(results.get(i)==results.get(i-1)){
				results.remove(i);
				int new_value=results.remove(i-1)+1;
				results.add(new_value);
				//System.out.println("iam removing "+results.get(i-1)+" and adding "
				//+new_value+" array size is "+results.size());
			}
		}
	}
	}


package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int value = scanner.nextInt();
        StringBuffer sb = new StringBuffer();
        while (value > 0) {
            int pw = (int) lg(value);
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(String.valueOf(pw + 1));
            value = value - powInt(pw);
        }
        System.out.println(sb.toString());
    }

    private static int powInt(int i) {
        return (int) Math.pow(2, i);
    }

    private static double lg(int x) {
        return (Math.log(x) / Math.log(2));
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class E {

    static class cup {
        int x, i, i0;

        cup(int i, int i0) {
            this.i=i; this.i0=i0;
        }
    }

    static cup find_cup(TreeSet<cup> t, int y, int lo, int hi) {
        cup aux=new cup(0, 0);
        while(lo<=hi) {
            int mid=(lo+hi)>>1;
            aux.i=mid;
            SortedSet<cup> sub=t.headSet(aux);
            if(sub.size()==y) {
                return sub.last();
            } else if(sub.size()<y) {
                lo=mid+1;
            } else {
                hi=mid-1;
            }
        }
        throw new IllegalStateException();
    }

    static void run_stream(InputStream ins) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] nm=br.readLine().split(" ");
        int n=Integer.parseInt(nm[0]);
        int m=Integer.parseInt(nm[1]);

        TreeSet<cup> t=new TreeSet<cup>(new Comparator<cup>() {
            public int compare(cup o1, cup o2) {
                return o1.i-o2.i;
            }
        });

        for (int i=0; i<n; i++) {
            t.add(new cup(m+i, i));
        }

        for (int i=1; i<=m; i++) {
            String[] xy=br.readLine().split(" ");
            int x=Integer.parseInt(xy[0]);
            int y=Integer.parseInt(xy[1]);

            cup c=find_cup(t, y, m-i, n+m);
            if(c.x>0&&c.x!=x) {
                System.out.println("-1");
                return;
            } else {
                c.x=x;
            }
            t.remove(c);
            c.i=m-i;
            t.add(c);
        }

        int[] out=new int[n];
        boolean[] b=new boolean[n+1]; int j=1;
        for (cup c: t) {
            if(c.x==0) {
                while(b[j]) {
                    j++;
                }
                c.x=j;
            }
            if(b[c.x]) {
                System.out.println("-1");
                return;
            }
            b[c.x]=true;
            out[c.i0]=c.x;
        }

        StringBuilder sb=new StringBuilder();
        for (int i=0; i<n; i++) {
            sb.append(out[i]+" ");
        }
        System.out.println(sb.toString());
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
    }

}


import java.util.*;
import java.io.*;

public class Test2 {

	static int graph[][];

	public static void main(String[] args) throws IOException {
		fjeiqwofjeqwiopfjewqoijifewq
	}

	public static int bfs(int N) {
		int flow = 0, par[] = new int[N+1], min[] = new int[N+1];
		LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(1);
		while(!ll.isEmpty()) {
			int n = ll.pop(); for(int i = 1; i<=N; i++) if(graph[n][i] > 0 && par[i] == 0) {
				par[i] = n; min[i] = Math.min(min[n], graph[n][i]); ll.add(i);
			}
		}
		if(par[N] == 0) return 0;
		flow = min[N]; int crnt = N; while(crnt != 1) {
			graph[par[crnt]][crnt] -= flow; graph[crnt][par[crnt]] += flow; crnt = par[crnt];
		}
		return flow;
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	public void close() throws IOException {
		if (din == null)
			return;
		din.close();
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package codeforces;
import java.util.*;
/**
 *
 * @author Ashraf
 */
public class cFA1 {
    public static void main(String []args){
        String s="";
        char c[]=new char[100];
        Scanner input=new Scanner(System.in);
        s=input.nextLine();
        c=s.toCharArray();
        boolean bool=false;
        int p=s.length();
        if(p==1){
            System.out.println("YES");
        }
        else{
        LeadingZero lz=new LeadingZero(p, c);
        if(c[p-1]=='0') s=lz.loop()+s;
        c=s.toCharArray();
        p=s.length();
        if(p%2==0){
            for(int i=0;i<p/2;++i){
                if(c[i]==c[--p]){
                    continue;
                }
                else{
                    bool=true;
                    break;
                }
            }
        }
        else{
            for(int i=0;i<(p/2)+1;++i){
                if(c[i]==c[--p]){
                    continue;
                }
                else{
                    bool=true;
                    break;
                }
            }
        }
        if(bool){
            System.out.println("NO");
        }
        else {
            System.out.println("YES");
        }
        }
    }

}


import java.util.*;
public class Main {
	public static void main(String []args){
		Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			long a=input.nextLong();
			long b=input.nextLong();
			String sa=new String(Long.toBinaryString(a));
			String sb=new String(Long.toBinaryString(b));
			int ans=0;
			int i,j,sa0=0,sb0=0;
			for(i=0;i<sa.length();i++)if(sa.charAt(i)=='0')sa0++;
			for(j=0;j<sb.length();j++)if(sb.charAt(j)=='0')sb0++;
			for(i=0;i<sa.length();i++)if(sa.charAt(i)=='0')break;
			for(j=0;j<sb.length();j++)if(sb.charAt(j)=='0')break;

			if(sa.length()==sb.length()){
				if(a==b&&sa0==1)ans=1;
			    els ans=i-j;
			}
			else{
				ans+=sa.length()-1-i;
				ans+=j;
			}

			if(sb.length()-sa.length()>=2){
				ans+=(sb.length()-2+sa.length())*(sb.length()-sa.length()-1)/2;
			}
		System.out.println(ans);
	}

}
	}


import java.util.Scanner;

public class tennis {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] dp = new long[10000];
		dp[0] = 1;
		dp[1] = 2;
		int i = 1;
		while(true){

				dp[i + 1] = dp[i] + dp[i - 1];
			if(dp[i] > n)
				break;
			i++;

		}
		if(i==1 )
			System.out.println(i);
		else
			System.out.println(i - 1);
	}
}


import java.math.*;
import java.util.*;
public class CodeForces
{
    public static void main(String[] args)
    {
      Scanner sc = new Scanner(System.in);
      int a,b,c;
      a=sc.nextInt();
      b=sc.nextInt();
      c=sc.nextInt();

      int x=abs(b-a)+abs(c-a);
      int y=abs(a-b)+abs(c-b);
      int z=abs(a-c)+abs(b-c);
      x=Math.min(x, y);
      y=Math.min(x, z);
      System.out.println(y);
    }
}


import static java.lang.Math.abs;
import static java.util.Arrays.*;
import java.util.Scanner;

public class Main  {

   public static void main(String[] args)  {

        int [] friends =new int[3];
        Scanner scan = new Scanner(System.in);
	for (int i = 0; i < 3; i++)
		 friends[i] = scan.nextInt();
	sort(friends);
        System.out.println(abs(friends[1] - friends[0]) + abs(friends[1] - friends[2]));

    }


package cf401Div2;

import java.util.Scanner;

public class ShellGame {

	public int solve(int n, int p) {
		if(p == 0) {
			return solve(n % 2 == 0 ? n + 1 : n + 2, 1);
		}
		if (p == 2) {
			return solve(n % 2 == 0 ? n + 2 : n + 1, 1);
		}
		if (n % 3 == 0) {
			return 1;
		}
		if (n % 3 == 1) {
			return 0;
		} else {
			return 2;
		}
	}

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int p = scanner.nextInt();
			System.out.println(new ShellGame().solve(n, p));
		}
	}

}


import java.io.InputStream;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        long x,y,a,b;
            InputStream inputStream = System.in;
//            OutputStream outputStream = System.out;
            Scanner in = new Scanner(inputStream);
//            PrintWriter out = new PrintWriter(outputStream);

            x=in.nextInt();
            y=in.nextInt();
            a=in.nextInt();
            b=in.nextInt();
            long count=0;
            long x_,y_;
            long xmin,xmax;
            x_=Math.max(x, y);
            y_=Math.min(x, y);
            if (x_%y_==0)count=(b-a)/x_;
            else{
                xmin=a/x_;
                if(a%x_>0)xmin++;
                xmax=b/x_;
                for(long i=xmin;(x_*i)<=b;i++){
                    if (((i*x_)%y_==0))count++;
                }}

            System.out.println(count);

    }


import java.util.*;

public class r589c {
	static final int MOD=1000000007;
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int x=scan.nextInt();
		long n=scan.nextLong();
		ArrayList<Integer> set=new ArrayList<>();
		for(int i=2;i*i<=x;i++) {
			if(x%i==0) {
				set.add(i);
				while(x%i==0) x/=i;
			}
		}
		set.add(x);
		long res=1L;
		for(int i=0;i<set.size();i++) {
			int fac=set.get(i);
			long ct=0;
			for(int j=1;;j++) {
				long add=n/pow(fac,j);
				ct+=add;
				if(add==0) break;
				if(n/fac<pow(fac,j)) break;
			}
			//			System.out.println(fac+" "+ct);
			//			System.out.println(pow(fac,ct));
			res=(res*powmod(fac,ct))%MOD;
		}
		System.out.println(res);
	}
	public static long pow(long i, long j) {
		long res=1L;
		for(int a=0;a<j;a++) res*=i;
		return res;
	}
	public static long powmod(long i, long j) {
		if(j==0) return 1L;
		if(j%2==0) {
			long temp=powmod(i,j/2);
			return (temp*temp)%MOD;
		}
		return (i*powmod(i,j-1))%MOD;
	}
}


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class P589C
{

	public static ArrayList<Integer> sieveFactors(int n)
	{
		boolean[] composite = new boolean[n + 1];
		int cap = (int)Math.round(Math.sqrt(n));

		for (int i = 2; i <= cap; i++)
			for (int j = 2; i * j <= n; j++)
				composite[i * j] = true;

		ArrayList<Integer> primes = new ArrayList<>();

		for (int i = 2; i <= cap; i++)
			if (!composite[i] && n % i == 0)
				primes.add(i);

		return primes;
	}

	public static void main(String[] args) throws ArithmeticException
	{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		long n = Long.parseLong(sc.next());

		ArrayList<Integer> factors = sieveFactors(x);

		BigInteger prod = BigInteger.ONE;
		BigInteger bigX = BigInteger.valueOf(x);
		// System.out.println(factors.toString());

		BigInteger m = new BigInteger("1000000007");

		for (int p = 0; p < factors.size(); p++)
		{
			long div = factors.get(p);
			int k = 0;

			while (div > 0 && div <= n)
			{
				k += n / div;
				div = div * factors.get(p);
			}

			// System.out.println(BigInteger.valueOf(factors.get(p)).pow(k));
			prod = prod.multiply(BigInteger.valueOf(factors.get(p)).pow(k));
		}

		// for (long i = 1; i <= n; i++)
		// {
		// 	// System.out.printf("dividing %d...\n", i);

		// 	// for (int p = 0; p < factors.size(); p++)
		// 	// {
		// 	// 	long curr = i;
		// 	// 	while (curr >= factors.get(p) && curr % factors.get(p) == 0)
		// 	// 	{
		// 	// 		// System.out.printf("%d divisible by %d\n", i, factors.get(p));
		// 	// 		prod = prod.multiply(BigInteger.valueOf(factors.get(p)));
		// 	// 		curr /= factors.get(p);
		// 	// 	}
		// 	// }

			// prod = prod.multiply(bigX.gcd(BigInteger.valueOf(i)));
		// }

		// System.out.println(prod.toString());
		System.out.println(prod.mod(m).toString());
	}
}


/**
 * ******* Created by K1K on 29/9/19 6:29 PM*******
 */

import java.io.*;
import java.util.*;

public class C1228 implements Runnable {
    List<Integer> primes = new ArrayList<>();
    public static final int MAX =(int) (1E5+100);
    public static final int MOD =(int) (1E9+7);
    boolean[] flag = new boolean[MAX];
    private void solve() throws IOException {
        int x = reader.nextInt();
        long n = reader.nextLong();
        sieve();
        for(int i=0;i<MAX;i++)if(!flag[i])primes.add(i);
        List<Integer> p = new ArrayList<>();
        int temp =x;
        for(int i=0;i<primes.size() && temp>0;i++){
            if(temp% primes.get(i)==0){
                while(temp >0 && temp%primes.get(i)==0)temp/=primes.get(i);
                p.add(primes.get(i));
            }
        }
        if(temp>0)p.add(temp);
        if(p.size() ==0){
            System.out.println("0");
            return;
        }
        long ans =1;
        for(int i=0;i<p.size();i++){
            long p1 = p.get(i);
            long t =n;
            while(t>0){
                long tem = t/p1;
                long val =power(p.get(i),tem)%MOD;
                ans = (ans * val) %MOD;
                t/=p.get(i);
            }
        }
        System.out.println(ans);
    }

    private long power(long a, long b) {
        long res =1;
        while(b>0){
            if(b%2 ==1)res =(res*a)%MOD;
            a= (a*a)%MOD;
            b/=2;
        }
        return res;
    }

    private void sieve() {
        flag[0] = true;
        flag[1]=true;
        for(int i=2;i*i<MAX;i++){
            if(!flag[i]){
                for(int j=i*i;j<MAX;j+=i){
                    flag[j]=true;
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new C1228().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}


import java.util.*;
import java.lang.*;
// StringBuilder uses java.lang

public class mainClass {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> listOfPrimes = new ArrayList<>();
        int r = n*1;
        for (int i=2;i<=Math.sqrt(n);i++) {
            if (r == 1) {
                break;
            }
            if (r % i == 0) {
                listOfPrimes.add(i);
            }
            int t = 0;
            while(r % i == 0) {
                t+=1;
                r/=i;
            }
        }
        if (r>1) {
            listOfPrimes.add(r);
        }
        long g = sc.nextInt();
        long ans = 1;
        for (int i=0;i<listOfPrimes.size();i++) {
            if (listOfPrimes.get(i)>g) {
                break;
            }
            long l = listOfPrimes.get(i);
            for (int j=1;j<62;j++) {
                long ok = g/l;
                ans*=fastPow(listOfPrimes.get(i),(ok % 1000000006),1000000007);
                ans%=1000000007;
                if (g/listOfPrimes.get(i)<l) {
                    break;
                }
                l*=listOfPrimes.get(i);
            }
        }
        System.out.println((ans+1000000007)%1000000007);
    }
    public static long fastPow(int base,long exp,int mod) {
        if (exp==0) {
            return 1;
        } else {
            if (exp % 2 == 1) {
                long z = fastPow(base,(exp-1)/2,mod);
                return ((((z*base) % mod) * z) % mod);
            } else {
                long z = fastPow(base,exp/2,mod);
                return ((z*z) % mod);
            }
        }
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class C {
	public static long mod = (long)(1e9+7);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner fr = new Scanner(System.in);
		int x = fr.nextInt();
		long n = fr.nextLong();
		ArrayList<Integer> prime_factors = prime_factors(x);
		long ans = 1;

		for(int val: prime_factors) {
			int prime = val;
			long count = 0;
			long times = n / prime;

			while(times > 0) {
				count += times;
				times = times / prime;
			}

			count = count % (mod - 1);
			ans = ans * pow(prime, count);
		}

		ans = ans % mod;
		System.out.println(ans);

	}

	public static long pow(int base, long exp) {
		if(exp == 0) {
			return 1;
		}

		long ans = pow(base, exp / 2);
		ans = ans % mod;

		ans = ans * ans;
		ans = ans % mod;

		if(exp % 2 == 1) {
			ans = ans * base;
			ans = ans % mod;
		}

		return ans;
	}

	public static ArrayList<Integer> prime_factors(int x){
		boolean bool[] = new boolean[x+1];
		bool[0] = bool[1] = true;
		for(int i=2;i<=x;i++) {
			if(!bool[i]) {
				int j = 2;
				while(i * j <= x) {
					bool[i * j] = true;
					j++;
				}
			}
		}

		ArrayList<Integer> arr = new ArrayList<>();
		for(int i=2;i<=x;i++) {
			if(!bool[i] && x % i == 0) {
				arr.add(i);
			}
		}

		return arr;
	}

}


import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class C_big {
    static boolean isPrime[];
    static int primes[];

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        sieve((int) 1e5);
        int x = in.nextInt();
        long n = in.nextLong();
        ArrayDeque<Integer> pf = primeFactors(x);
        long ans = 1, mod = (long) 1e9 + 7;
        BigInteger N = BigInteger.valueOf(n);
        for (int p : pf) {
            BigInteger P = BigInteger.valueOf(p);
            for (BigInteger i = P; i.compareTo(N) <= 0; i = i.multiply(P)) {
                long d = n / i.longValue();
                ans = (ans * bigMod(p, d, mod)) % mod;
            }
        }

        pw.println(ans);

        pw.close();
    }

    static long bigMod(long a, long p, long m) { // returns (a^p) % m
        long res = 1 % m, x = a % m;
        while (p > 0) {
            if ((p & 1) > 0) res = (res * x) % m;
            x = (x * x) % m;
            p >>= 1;
        }
        return res;
    }

    static ArrayDeque<Integer> primeFactors(int n) {
        ArrayDeque<Integer> pf = new ArrayDeque<>();
        for (int p : primes) {
            if (n <= 1) break;
            if (n % p == 0) {
                pf.addLast(p);
                while (n % p == 0) n /= p;
            }
        }
        if (n > 1) pf.addLast(n);
        return pf;
    }

    static int[] sieve(int n) {
        isPrime = new boolean[n + 1];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 4; i <= n; i += 2) isPrime[i] = false;
        for (int i = 3; i * i <= n; i += 2) {
            if (isPrime[i]) {
                for (int j = i * i; j <= n; j += 2 * i)
                    isPrime[j] = false;
            }
        }
        primes = new int[n + 1];
        int idx = 0;
        primes[idx++] = 2;
        for (int i = 3; i <= n; i += 2) {
            if (isPrime[i]) {
                primes[idx++] = i;
            }
        }
        return Arrays.copyOf(primes, idx);
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);

		long m=1000000007;

		long x=s.nextLong();
		long n=s.nextLong();

		boolean[] prime=new boolean[500001];

		seive(prime,500000);

		ArrayList<Long> list=new ArrayList<>();

		for(long i=2;i<=500000;i++)
		{
			if(prime[(int)i]&&x%i==0)
			{
				list.add(i);
				x=x/i;
			}
		}

		list.add(x);

		//System.out.println(list);

		long ans=1;

		for(int i=0;i<list.size();i++)
		{
			long count=0;

			for(long j=list.get(i);j<=n;j=j*list.get(i))
			{
				count=count+(n/j);
				if(Long.MAX_VALUE/j<list.get(i))
					break;
			}

			ans=(ans%m*power(list.get(i),count,m))%m;

		}

		System.out.println(ans);

	}

	public static long power(long a,long b,long m)
	{
		long res=1;

		while(b>0)
		{
			if(b%2!=0)
			{
				res=(res%m*a%m)%m;
			}

			b=b/2;
			a=(a%m*a%m)%m;
		}

		return res;
	}

	public static void seive(boolean[] prime,int n)
	{
		Arrays.fill(prime,true);

		prime[0]=false;
		prime[1]=false;

		for(int i=2;i<=Math.sqrt(n);i++)
		{
			if(prime[i])
			{
				for(int j=i*i;j<=n;j=j+i)
				{
					prime[j]=false;
				}
			}
		}
	}

}