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

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = false;

	static long[] primes;
	static int p_count;

	public static void get_primes(int n)
	{
		primes = new long[80000];

		boolean[] v = new boolean[n+1];
		int i,j;
		for (i=2; i<=n;i++)
		{
			v[i] = true;
		}

		for (i=2; i*i<=n;i++)
		{
			if (v[i])
			{
				for (j=i; i*j<=n; j++)
				{
					v[i*j]=false;
				}
			}
		}

		p_count = 0;
		for (i=2; i<=n; i++)
		{
			if (v[i])
			{
				primes[p_count++] = i;
			}
		}
	}

	int d_count;
	int[] d_index;
	long A;

	public int d_index(long x)
	{
		if ( (x<1000000) && (x*x<=A))
		{
			return d_index[(int)x];
		}
		else
		{
			return d_count - d_index[(int)(A/x)] - 1;
		}
	}

	public void test()
	{
		A = readLong();

		if (A==1)
		{
			out.println(1);
			return;
		}

		get_primes(1000000);

		long[] dividers = new long[10000];
		d_count = 0;

		d_index = new int[1000000];

		long[] use_primes = new long[10000];
		int use_p_count = 0;

		boolean[] p_used = new boolean[1000000];
		Arrays.fill(p_used, false);

		int i;
		for (i=1; i*i<=A; i++)
		{
			if (A % i == 0)
			{
				d_index[i] = d_count;
				dividers[d_count++] = i;
			}
		}

		for (i=0; i<d_count; i++)
		{
			dividers[2*d_count-i-1] = A / dividers[i];
		}

		d_count *= 2;

		long d;
		int p;
		boolean is_prime;

		for (i=1; i<d_count; i++)
		{
			is_prime = true;
			d = dividers[i]-1;

			if (d==1) continue;

			for ( p=0; p<p_count; p++)
			{
				if (primes[p]*primes[p] > d)
				{
					break;
				}

				if (d % primes[p] == 0)
				{
					is_prime = false;
					while (d % primes[p] == 0)
					{
						d /= primes[p];
					}
					if (d==1)
					{
						if (!p_used[(int)primes[p]])
						{
							p_used[(int)primes[p]] = true;
							use_primes[use_p_count++] = primes[p];
						}
					}
				}
			}

			if (is_prime)
			{
				if ((d > 1000000) || !p_used[(int)d])
				{
					if (d<1000000)
					{
						p_used[(int)d] = true;
					}
					use_primes[use_p_count++] = d;
				}
			}
		}

		logWrite("use_p_count = %d\n", use_p_count);

		long[] D = new long[d_count];
		long[] D1 = new long[d_count];

		Arrays.fill(D, 0);
		D[0] = 1;

		for (p=0; p<use_p_count; p++)
		{
			logWrite("P = %d\n", use_primes[p]);
			for (i=1; i<d_count; i++)
			{
				D1[i] = D[i];
				d = use_primes[p];
				while (d<dividers[i])
				{
					if (dividers[i] % (d+1) == 0)
					{

						//logWrite("D1[%d] += D[%d] = %d + %d  \n", i,  d_index(dividers[i] / (d+1)), D1[i], D[d_index(dividers[i] / (d+1))]);

						D1[i] += D[d_index(dividers[i] / (d+1))];
					}

					d *= use_primes[p];
				}
			}

			for (i=1; i<d_count; i++) D[i] = D1[i];
		}

		out.println(D[d_count-1]);
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

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

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


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

public class Main
{

    public static void process()throws IOException
    {
        int HP_y=ni(),ATK_y=ni(),DEF_y=ni();
        int HP_m=ni(),ATK_m=ni(),DEF_m=ni();
        int h=ni(),a=ni(),d=ni(),res=Integer.MAX_VALUE,cost;

        for(int i=0;i<=200;i++){
            for(int j=0;j<=200;j++){
                //for(int k=0;k<=100;k++){

                    int hp_y=HP_y,atk_y=ATK_y+i,def_y=DEF_y+j;

                    int hp_m=HP_m;

                    while(hp_m>0){
                        hp_m-=Math.max(0,(atk_y-DEF_m));
                        hp_y-=Math.max(0,ATK_m-def_y);
                    }

                    cost=i*a+j*d;
                    if(hp_y<=0){
                        //pn("monster vs yang "+hp_m+" "+hp_y);
                        //res=Math.min(res, k*h+i*a+j*d);//k->hp i->attack j->defence
                        cost+=((-hp_y+1)*h);
                    }

                    res=Math.min(cost, res);
               // }
            }
        }

        pn(res);
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

        oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;
    static long mod=(long)1e9+7l;

    static void r_sort(int arr[],int n){
        Random r = new Random();
        for (int i = n-1; i > 0; i--){
            int j = r.nextInt(i+1);

            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        Arrays.sort(arr);
    }

    static long mpow(long x, long n) {
        if(n == 0)
            return 1;
        if(n % 2 == 0) {
            long root = mpow(x, n / 2);
            return root * root % mod;
        }else {
            return x * mpow(x, n - 1) % mod;
        }
    }

    static long mcomb(long a, long b) {
        if(b > a - b)
            return mcomb(a, a - b);
        long m = 1;
        long d = 1;
        long i;
        for(i = 0; i < b; i++) {
            m *= (a - i);
            m %= mod;
            d *= (i + 1);
            d %= mod;
        }
        long ans = m * mpow(d, mod - 2) % mod;
        return ans;
    }
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}


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

import static java.lang.Math.*;

public class Cf86 implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		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 String nextLine()
        {
		String str = "";
		try
		{
			str = br.readLine();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return str;
	}
        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 long nextLong()
        {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		long res = 0;

		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		}
		while (!isSpaceChar(c));
			return res * sgn;
        }

        public double nextDouble()
        {
		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 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 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);
	}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Cf86(),"Main",1<<27).start();
	}
	public void run()
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		int sum=0;
		for(i=2;i<n;i++)
		{
		    sum=sum+(i*(i+1));
		}
		w.println(sum);
		System.out.flush();
		w.close();
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class D1140 {

	public static void main(String[] args) throws NumberFormatException, IOException {
//		BufferedReader br = new BufferedReader(new FileReader("F:/books/input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		long tot = 0;
		for(int i=2;i<n;i++) {
			tot += i*(i+1);
		}
		System.out.println(tot);
	}

}


package challenge2;
import java.util.Scanner;
public class Train12 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int days =  sc.nextInt();
		String nDays = sc.next();
		int flightstoF = 0;
		int flightstoS = 0;

		for(int i = 1; i < nDays.length(); i++)
			if(nDays.charAt(i - 1) != nDays.charAt(i))
				if(nDays.charAt(i) == 'F')
					flightstoF++;
				else
					flightstoS++;

		if(flightstoF > flightstoS)
			System.out.println("YES");
		else
			System.out.print("NO");

	}

}


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

public class Main{
  /*
  .
  .
  .
  .
  .
  .
  .
  some constants
  .
  */
  /*
  .
  .
  .
  if any
  .
  .
  */
  public static void main(String[] args) throws IOException{
		/*
		.
		.
		.
		.
		.
		.
    */
    int n=ni();
    int m=ni();
    int one=Integer.MAX_VALUE;
    int two=Integer.MAX_VALUE;
    for(int i=0;i<n;i++)
      one=Math.min(one,ni());
    for(int i=0;i<m;i++)
      two=Math.min(two,ni());
    if(one==two){
      sop(one);
    }
    else{
      sop(Math.min(one*10+two,two*10+one));
    }
    /*
		.
		.
		.
		.
		.
		.
		.
		*/
	}
	/*
	temporary functions
	.
	.
	*/
	/*
	fuctions
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	abcdefghijklmnopqrstuvwxyz
	.
	.
	.
	.
	.
	.
	*/
	static int modulo(int j,int m){
		if(j<0)
			return m+j;
		  if(j>=m)
			return j-m;

			return j;
	}
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	static StringBuilder ans=new StringBuilder();
	static long powm(long a,long b,long m){
		long an=1;
		long c=a;
		while(b>0){
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void sop(Object a){System.out.println(a);}
	static int ni(){return in.nextInt();}
	static int[] nia(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=ni();return a;}
	static long nl(){return in.nextLong();}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String ns(){return in.next();}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double nd(){return in.nextDouble();}
	static double[] nda(int n){double a[]=new double[n];for(int i=0;i<n;i++)a[i]=nd();return a;}
	static class Reader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public Reader(){
			reader=new BufferedReader(new InputStreamReader(System.in),32768);
			tokenizer=null;
		}
		public String next(){
			while(tokenizer==null || !tokenizer.hasMoreTokens()){
				try{
					tokenizer=new StringTokenizer(reader.readLine());
				}
				catch(IOException e){
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
	}
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = 1; i <= test_cases; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }
}

class Solver {
    void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        int ans = 1;
        while (true) {
            if (Arrays.binarySearch(a, ans) > -1 && Arrays.binarySearch(b, ans) > - 1) {
                out.println(ans);
                return;
            }
            ++ans;
        }
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

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

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
 public class Main{
public static void main(String args[]) throws IOException
{
    Scanner ravi=new Scanner(System.in);

        int a=ravi.nextInt();
        int b=ravi.nextInt();
        PriorityQueue<Integer> q=new PriorityQueue<>();
         PriorityQueue<Integer> qh=new PriorityQueue<>();
         for(int i=0;i<a;i++)q.add(ravi.nextInt());
         	for(int i=0;i<b;i++)qh.add(ravi.nextInt());

          int m=q.poll();
          int n=qh.poll();
          if(m==n)System.out.println(m);
          else
          {
          	int k=Math.min(m,n);
          	int kk=Math.max(m,n);
          	System.out.println((k*10+kk));
          }

     } }


import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;

public class cf2d40c {
	//PrintWriter out;
    public static void main(String[] args) throws IOException {
		//System.setIn(new FileInputStream("input.txt"));
		//System.setOut(new PrintStream("output.txt"));
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
	//Scanner s = new Scanner(System.in);
	String s = r.readLine();
	int n = s.length();
	String a = "";
	for(int i = 0; i < n; i++) {
		if(i < n-3 && s.charAt(i) == 'd' && s.charAt(i+1) == 'o' && s.charAt(i+2) == 't') {
			a += ".";i++;i++;
		}
		else a += s.charAt(i);
	}
	n = a.length();int b = 0;
	String c = "";
	for(int i = 0; i < n ; i++) {
                if(i < n-2 && a.charAt(i) == 'a' && a.charAt(i+1) == 't' && b == 0) {
                        c += "@";i++;b = 1;
                }
                else c += a.charAt(i);
        }
	n = c.length();
	if(c.charAt(0) == '.') { c = "dot" + c.substring(1);}
	 n = c.length();
        if(c.charAt(0) == '@') { c = "at" + c.substring(1);}
	 n = c.length();
        if(c.charAt(n-1) == '.') { c = c.substring(0,n-1) + "dot";}
	System.out.println(c);

	}
}


package com.company.Sorting;

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

public class EightPointSets {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] x = new int[8];
        int[] y = new int[8];
        for (int i = 0; i < 8; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        for(int i=0;i<8;i++){
            for(int j=i+1;j<8;j++) {
                if (x[i] == x[j] && y[i]==y[j]) {
                    System.out.println("ugly");
                    return;
                }
            }
        }

        int[] cntx = new int[1000000 + 1];
        int[] cnty = new int[1000000 + 1];
        for(int i=0;i<8;i++){
            cntx[x[i]]++;
            cnty[y[i]]++;
        }
        boolean isRespectable = false;
        Arrays.sort(x);
        Arrays.sort(y);
        if (cntx[x[0]] == 3 && cntx[x[3]] == 2 && cntx[x[5]] == 3
                && cnty[y[0]] == 3 && cnty[y[3]] == 2
                && cnty[y[5]] == 3) {
            isRespectable = true;
        }
        System.out.println(isRespectable ? "respectable" : "ugly");
    }
}


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

public class A627 {
	static int [] a = new int [100]; // a is the sum
	static int [] b = new int [100]; // b is the xor
	final static int bit = 50;

	static long [][] fn = new long [100][500];

	static long dp (int x, int carry) {
		if(x == bit) {
			if(carry == 0) return 1;
			else return 0;
		}
		long ans = 0;
		for(int i = 0; i <= 1; i++) {
			for(int j = 0; j <= 1; j++) {
				int xor = i ^ j;
				int sum = i + j + carry;
				if(xor == b[x] && (sum % 2) == a[x]) {
					ans += dp(x + 1, (sum / 2));
				}
			}
		}
		return fn[x][carry] = ans;
	}
	public static void main(String[] args) {
		Reader in = new Reader ();
		long p = in.nextLong();
		long q = in.nextLong();

		for(int i = 0; i < 100; i++) Arrays.fill(fn[i], -1);
		for(int i = 0; i <= bit; i++) {
			a[i] = (int) ((p >> i) & 1);
			b[i] = (int) ((q >> i) & 1);
		}
		long ans = dp(0, 0);
		if(p == q) ans -= 2;
		System.out.println(ans);
	}
	static class Reader {
		BufferedReader a;
		StringTokenizer b;
		Reader () {
			a = new BufferedReader (new InputStreamReader (System.in));
		}
		String next () {
			while(b == null || !b.hasMoreTokens()) {
				try {
					b = new StringTokenizer (a.readLine());
				} catch (IOException e) {
					e.printStackTrace ();
				}
			}
			return b.nextToken ();
		}
		int nextInt () {
			return Integer.parseInt(this.next());
		}
		long nextLong() {
			return Long.parseLong(this.next());
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashMap;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskC {
        int MAXINDEX = 40;
        long wantsum;
        long wantxor;
        HashMap<Long, Long> goodmem = new HashMap<>();

        long toval(int index, long sum, boolean anonzero, boolean bnonzero) {
            long res = (sum << 8);
            res += index;
            res <<= 1;
            res += (anonzero ? 1 : 0);
            res <<= 1;
            res += (bnonzero ? 1 : 0);
            return res;
        }

        long dp(int index, long sum, boolean anonzero, boolean bnonzero) {
            if(sum > wantsum) return 0;
            if(index >= MAXINDEX) {
                return (anonzero && bnonzero && sum == wantsum) ? 1 : 0;
            }
//        if (index >= MAXINDEX - 1 && sum == wantsum) ;
            if(sum != wantsum && sum + (1L << index) > wantsum) return 0;
            long memval = toval(index, sum, anonzero, bnonzero);
//        HashMap<Long, Long> memref = mem[index][anonzero ? 1 : 0][bnonzero ? 1 : 0];
//        if (memref == null) mem[index][anonzero ? 1 : 0][bnonzero ? 1 : 0] = new HashMap<>();
//        memref = mem[index][anonzero ? 1 : 0][bnonzero ? 1 : 0];
//        if (memref.containsKey(sum)) return memref.get(sum);
            if(goodmem.containsKey(memval)) return goodmem.get(memval);
            int bitatindex = (int) ((wantxor >> index) & 1);
            long res = 0;

            if(sum == wantsum && bitatindex == 0) res = dp(index + 1, sum, anonzero, bnonzero);
            else {
                for(int bita = 0; bita < 2; bita++) {
                    for(int bitb = 0; bitb < 2; bitb++) {
                        int bitval = bita ^ bitb;
                        if(bitval != bitatindex) continue;
                        long moar = 0;
                        if(bita == 1) moar += (1L << index);
                        if(bitb == 1) moar += (1L << index);
                        res += dp(index + 1, sum + moar, anonzero ? anonzero : bita == 1, bnonzero ? bnonzero : bitb == 1);
                    }
                }
            }
            goodmem.put(memval, res);
            return res;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long s = in.readLong(), x = in.readLong(), res = 0;
            wantsum = s;
            wantxor = x;
            long otherres = dp(0, 0, false, false);
            out.printLine(otherres);
        }

    }

    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 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 isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }

    static 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 close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }
}


import java.util.*;
import java.io.*;
public class Xor1
{
  public void fun()
  {
    Scanner in= new Scanner(System.in);
	long s = in.nextLong();
	long s1=s;
	long x = in.nextLong();
	if(x==0)
	{
	  System.out.println("1");
	  return;
	 }
	long c=0;
	for(long i=1;i<=s;i++)
	{
	 for(long j=i+1;j<=s;j++)
	 {
	  if(((i+j)==s1)&&((i^j)==x))
	  {
	    c=c+2;
	  }
     }
    }
    System.out.println(c);

  }
  public static void main(String args[])
  {
    new Xor1().fun();
  }
}


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

      static int count(long n){

                     int c=0;
                     while(n>0)
                       { c++;n=n/2;}
                    return(c);
             }
        static class pair{
                       long x,y;
                      pair(long a,long b){
                             x=a;
                             y=b;
                       }

                   public boolean equals(Object obj) {
                         if (this == obj)
                                return true;
                        if (obj == null)
                                return false;
                        if (getClass() != obj.getClass())
                                return false;
                         pair other = (pair) obj;
                          if (x != other.x)
                                  return false;
                          if (y != other.y)
                                  return false;
                            return true;
                      }
                      @Override
                 public int hashCode() {
                      return((int)(x-y));
                   }
          }
    public static void main(String[] args) throws IOException {
         Scanner sc = new Scanner(System.in);

                long s = sc.nextLong();
                long x = sc.nextLong();
                int c = count(x);
                long a=0,b=0;
                     if(c==0){
                         if(s%2==0)
                             System.out.println("1");
                         else
                            System.out.println("0");
                     }
                   else{
                HashSet<pair> arr[] = new HashSet[c];
                       for(int i=0;i<c;i++)
                            arr[i] = new HashSet();
                    long x1=(1<<(c-1));
                    pair p1 = new pair(x1,0);
                    arr[c-1].add(p1);
                     p1 = new pair(0,x1);
                   arr[c-1].add(p1);

                       for(int i=c-2;i>=0;i--){
                             x1 = (1<<(i));
                          if((x&x1)!=0){

                               for(pair p : arr[i+1]){
                                       a = p.x; b=p.y;
                                       p1 = new pair(a+x1,b);
                                            arr[i].add(p1);
                                       p1 = new pair(a,b+x1);
                                            arr[i].add(p1);
                                }
                         }
                             else{
                                       for(pair p : arr[i+1]){
                                       a = p.x; b = p.y;
                                       p1 = new pair(a,b);
                                         arr[i].add(p1);
                                       if((a+b+2*x1)<=s){
                                                  p1 = new pair(a+x1,b+x1);
                                                  arr[i].add(p1);
                                       }
                                }
                            }
                      }
                  long ans=0;
                 for(pair p : arr[0])
                             if((p.x+p.y)==s&&p.x!=0&&p.y!=0)
                                   ans++;
                 System.out.println(ans);
               }
       }
       static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public 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 int nextInt() 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 long nextLong() 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 double nextDouble() 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 void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}


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

      static int count(long n){
                     int c=0;
                     while(n>0)
                       { c++; n=n/2; }
                    return(c);
             }
    public static void main(String[] args) throws IOException {
         Scanner sc = new Scanner(System.in);

                long s = sc.nextLong();
                long x = sc.nextLong();
                 long ans=0;
                  if((s-x)%2==1||(s-x)%2==-1)
                     ans=0;
                  else
                    {
                         long and = (s-x)/2;
                             if(x==0)
                                 ans=1;
                             int c = count(x);
                              for(int i=0;i<c;i++){
                                int t = 1<<i;

                                 if((x&t)==1){
                                     if((and&t)==0){
                                      if(ans==0)ans=2;
                                      else ans=ans*2;}
                                    else
                                      { ans=0;break}
                                  }
                                 x=x/2;
                              }
                             if(and==0&&ans>0)
                                 ans=ans-2;
                     }
                 System.out.println(ans);
       }
       static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public 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 int nextInt() 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 long nextLong() 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 double nextDouble() 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 void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}


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

public class nines {
    public static void main(String[] args) {
        InputStream input = System.in;
        OutputStream output = System.out;
        InputReader2 in = new InputReader2(input);
        PrintWriter out = new PrintWriter(output);
        Solution s = new Solution();
        s.solve(1, in, out);
        out.close();
    }

    static class Solution {

        double EPS = 0.0000001;
        public void solve(int cs, InputReader2 in, PrintWriter out) {
            String s = in.next();
            long p = Long.parseLong(s), k = in.nextLong();
            long d = p - p % (long)(Math.pow(10, s.length()-1)) - 1;
            while (p-d > k) {
                for (int n = s.length()-1; n > 0; --n) {
                    long pow = (long)(Math.pow(10, n));
                    while (d+pow < p) {
                        d+=pow;
                    }
                }
            }
            out.println(d);
        }
    }

   static class InputReader2 {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

        public int read() {
            if (numChars == -1) {
                throw new RuntimeException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0; // long or int
            do {
                if (c < '0' || c > '9') {
                    throw new RuntimeException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0, div = 1;
            do {
               res *= 10;
               res += c - '0';
               c = read();
            } while (c >= '0' && c <= '9');
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    res += (c - '0') / (div *= 10);
                }
            }
            return res * sgn;
        }
        public String next() {
            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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.util.HashSet;
import java.util.*;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.text.DecimalFormat;
import java.lang.Math;
public class Lo {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      int digits = 0;
      long temp = n;
      long t = temp%10;
      while(temp>0){
          digits++;
          temp /= 10;
      }
      long max = n;
      if(t+1 <= k){
          max = n-(t+1);
      }
      long d = (long)Math.pow(10, digits-1)-1;
      int p = 2;
      for(long i = n; i >= Math.max(d, n-k); i = i-10){
          if((i-(t+1))%(long)Math.pow(10,p) == (long)Math.pow(10,p)-1 && i-(t+1)>=(n-k)){
              max = i-(t+1);
              p++;
          }
      }
      if(k==0){
          System.out.println(n);
      }
      else{
          System.out.println(max);
      }
    }
}


import java.util.Scanner;

public class SuperPriceBourles {
    public static void main(String asd[])throws Exception
    {
        Scanner in=new Scanner(System.in);
        long n=in.nextLong();
        long d=in.nextLong();
        int k=1;
        while((n-(n - n % (int)Math.pow(10,k) - 1))<=d && n - n % (int)Math.pow(10,k) - 1!=-1)
        {
            n=n - n % (int)Math.pow(10,k) - 1;
            k++;
        }
        System.out.println(n);
    }
}


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

/**
 *
 * @author kreed96
 */
public class Test1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        BigInteger res;
        BigInteger factA = factorial(a);
        BigInteger factB = factorial(b);
        boolean trig = true;
        BigInteger nod;
        if(factA.longValue() > factB.longValue()) nod = factA;
        else if (factA.longValue() < factB.longValue()) nod = factB;
        else nod = factA;
        while(trig){
           if(nod == BigInteger.valueOf(0)) trig = false;
           else if(factA.divideAndRemainder(nod)[1] == BigInteger.valueOf(0) && factB.divideAndRemainder(nod)[1] == BigInteger.valueOf(0) ) trig = false;
           else nod = nod.subtract(BigInteger.valueOf(1));
        }
        res = nod;
        System.out.println(res);
    }

     public static  BigInteger factorial(int n)
    {
        if (n == 0) return BigInteger.ONE;
        return BigInteger.valueOf(n).multiply(factorial(n-1));
    }

}


import java.util.Scanner;

public class GCDOfFactorials {

	public static void main(String[] args)  {

		Scanner in = new Scanner(System.in);
        int num1 = in.nextInt();
        int num2 = in.nextInt();

		int fact[] = null;
		if(num1 > num2) {
			fact = factorial(num1);
		}
		else {
			fact = factorial(num2);
		}
		int fact1 = fact[num1];
		int fact2 = fact[num2];

		System.out.println(gcd(fact1, fact2));
	}

	private static int gcd(int a , int b) {
		if(a == 0) {
			return b;
		}
		return gcd(b%a,a);
	}

	private static int[] factorial(int num) {
		int[] arr = new int[num+1];
		arr[0] = 1;
		for(int i=1;i<=num;i++) {
			arr[i] = arr[i-1] * i;
		}
		return arr;
	}

}


import java.util.Scanner;

public class New {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next() ;

		if (S.charAt(0) == 'S' && S.charAt(-1)=='F'){
			System.out.println("YES");

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

}


import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    sc.nextLine();
        String vuelos = sc.nextLine();
        int S=0, F=0, C=0;
        for(int i=0; i<n; i++)
        {
            if(vuelos.charAt(i)=='F' && vuelos.charAt(i+1) == 'S')
            {
                F++;
                break;
            }
            else if(vuelos.charAt(i)=='S' && vuelos.charAt(i+1) == 'F')
            {
                S++;
                break;
            }
            else
            {
                C++;
            }

        }
        if(S>F)
            System.out.print("YES");
        else if(F>=S)
            System.out.print("NO");

	}
}


package com.test;

import java.util.Scanner;

public class Problem {

    public static void main(String [] args) {

        Scanner scanner  = new Scanner(System.in);

        StringBuilder sb1 = new StringBuilder(scanner.nextLine());
        StringBuilder sb2 = new StringBuilder(scanner.nextLine());
        int StoF = 0;
        int FtoS = 0;

        for(int i = 2 ; i < Integer.valueOf(sb1.toString()) ; i++)
        {
            if(sb2.substring(i-2,i).equals("SF"))
            {
                StoF++;
            }
            if(sb2.substring(i-2,i).equals("FS"))
            {
                FtoS++;
            }
        }
        if(StoF>FtoS)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }

        scanner.close();
    }
}


import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main{
     static BufferedReader in;
     static PrintWriter out;
     static StringTokenizer tok;
     static void solve() throws IOException{
          int r=Int();
          int x=Int();
          int y=Int();
          int x1=Int();
          int y1=Int();
          double dist=(int)Math.sqrt((long)Math.abs((long)(x1-x)*(x1-x))+(long)Math.abs((long)(y1-y)*(y1-y)));
         // int t=r*2;

          out.println((int)Math.ceil(dist/(2*r)));
     }
     static int Int() throws IOException{
          return parseInt(next());
     }
     static String next() throws IOException{
          while(tok==null || !tok.hasMoreTokens()){
               tok=new StringTokenizer(in.readLine());
          }
          return tok.nextToken();
     }
     public static void main(String args[]){
          try{
               in=new BufferedReader(new InputStreamReader(System.in));
               out=new PrintWriter(new OutputStreamWriter(System.out));
               solve();
               in.close();
               out.close();
          }catch(Throwable e){
               e.printStackTrace();
               exit(1);
          }
     }
}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

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

class TaskD {
    private final int MAX = 50;
    private long[] fib;

    public TaskD() {
        fib = new long[MAX + 1];
        fib[0] = 1;
        fib[1] = 1;
        for (int i = 2; i <= MAX; i++) fib[i] = fib[i - 1] + fib[i - 2];
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long k = in.nextLong();
        int[] res = new int[n + 1];
        fill(res, k, 1);
        for (int i = 1; i <= n; i++) out.print(res[i] + " ");
        out.println();
    }

    private void fill(int[] res, long rank, int pos) {
        if (pos == res.length) return;
        if (pos == res.length - 1) {
            res[pos] = pos;
            return;
        }
        int cnt = res.length - pos;
        if (rank < fib[cnt]) {
            res[pos] = pos;
            fill(res, rank, pos + 1);
        } else {
            res[pos] = pos + 1;
            res[pos + 1] = pos;
            fill(res, rank - fib[cnt], pos + 2);
        }
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

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

}


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

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

   long MAX = 1000000000000000008L;
   public B(FastScanner in, PrintWriter out)
   {
      int N = in.nextInt();
      long K = in.nextLong()-1;
      long[] ways = new long[N+1];
      ways[0] = 1L;
      for (int i=0; i<N; i++)
      {
         for (int k=1; i+k<=N; k++)
         {
            ways[i+k] += ways[i];
            ways[i+k] = Math.min(ways[i+k], MAX);
         }
      }

      int pos = 0;
      while (pos < N)
      {
         for (int i=pos; i<N; i++)
         {
            int numLeft = N-i-1;
            if (K < ways[numLeft])
            {
               for (int j=i; j>=pos; j--)
               {
                  out.print(j+1);
                  out.print(' ');
               }
               pos = i+1;
               break;
            }
            K -= ways[numLeft];
         }
      }
      out.println();

   }
}

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

   public FastScanner()
   {
      stream = System.in;
   }

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

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

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

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

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

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

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

   String nextLine(){
      int c = read();
      while (isEndline(c))
         c = read();
      StringBuilder res = new StringBuilder();
      do{
         res.appendCodePoint(c);
         c = read();
      }while(!isEndline(c));
      return res.toString();
   }
}


import java.util.InputMismatchException;
import java.io.InputStream;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;

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

class TaskB {
    private static final long MAX = 1000000000000000000L;
    private static final BigInteger LIM = BigInteger.valueOf(MAX);

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();
        long K = in.nextLong();

        BigInteger[] fact = new BigInteger[N + 1];
        fact[0] = BigInteger.ONE;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i - 1].multiply(BigInteger.valueOf(i));
            fact[i] = fact[i].min(LIM);
        }

        BigInteger[] dp2 = new BigInteger[N + 1];
        dp2[0] = BigInteger.ONE;
        for (int i = 1; i <= N; i++) {
            dp2[i] = BigInteger.ZERO;
        }
        for (int i = 0; i < N; i++) {
            for (int j = i; j < N; j++) {
                dp2[j + 1] = dp2[j + 1].add(dp2[i].multiply(fact[j - i]));
                dp2[j + 1] = dp2[j + 1].min(LIM);
            }
        }
        long[] dp = new long[N + 1];
        for (int i = 0; i <= N; i++) {
            dp[i] = Long.parseLong(dp2[i].toString());
        }
        if (dp[N] < K) {
            throw new RuntimeException();
        }

        int[] P = new int[N];
        boolean[] used = new boolean[N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (used[j]) continue;
                if (dp[N - i - 1] < K) {
                    K -= dp[N - i - 1];
                } else {
                    P[i] = j;
                    used[j] = true;
                    break;
                }
            }
        }

        for (int i = 0; i < N; i++) {
            if (i > 0) {
                out.print(" ");
            }
            out.print(P[i] + 1);
        }
        out.println();
    }
}

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

    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() {
        return Integer.parseInt(nextString());
    }

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

    public String nextString() {
        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;
    }

}


import java.util.*;
public class GFG {
	public static void main (String[] args)
	{
	    Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();int a[]=new int[26];int s1=0;
		if (n==1) {System.out.println(0);return;}
		for (int i=0;i<n;i++) a[s.charAt(i)-'a']++;
		//System.out.println(Arrays.toString(a));
		for (int i=25;i>=1;i--)
		{
		    char c=(char)('a'+i);
		    for (int j=0;j<s.length();)
		    {
		        if (s.charAt(j)==c)
		        {
		            if (j==0)
		            {
		                if (s.charAt(j+1)==c-1)
		                {
		                    s=s.substring(j+1,s.length());
		                    s1++;j--;
		                }
		            }
		            else if (j==s.length()-1)
		            {
		                if (s.charAt(j-1)==c-1)
		                {
		                    s=s.substring(0,j);
		                    s1++;j--;
		                }
		            }
		            else
		            {
		                if (s.charAt(j+1)==c-1 || s.charAt(j-1)==c-1)
		                {
		                    s=s.substring(0,j)+s.substring(j+1,s.length());
		                    s1++;j--;
		                }
		            }

		        }
		        j++;
		    }
		}
		System.out.println(s1);
	}
}


import java.util.Scanner;

public class A746 {
	public static void main(String[] args) throws FileNotFoundException{
		Scanner scanner = new Scanner(System.in);
		int lemonsMax = scanner.nextInt();
		int applesMax = scanner.nextInt() / 2;
		int pearsMax = scanner.nextInt() / 4;
		int compare1 = Math.min(applesMax, pearsMax);
		int maxCompost = Math.min(compare1, lemonsMax);
		int result = maxCompost * 7;
		System.out.print(result);
	}
}


import java.util.Scanner;

public class R386A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
		int count = 0;
		while (a > 0 && b > 0 && c > 0) {
			if (a - 1 < 0 || b - 2 < 0 || c - 4 < 0)
				break;
			if (a - 1 >= 0) {
				a--;
				++count;
			}

			if (b - 2 >= 0) {
				b -= 2;
				count += 2;
			}

			if (c - 4 >= 0) {
				c -= 4;
				count += 4;
			}

		}
		System.out.println(count);
	}

}
import java.util.Scanner;

public class R386A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
		int count = 0;
		while (a > 0 && b > 0 && c > 0) {
			if (a - 1 < 0 || b - 2 < 0 || c - 4 < 0)
				break;
			if (a - 1 >= 0) {
				a--;
				++count;
			}

			if (b - 2 >= 0) {
				b -= 2;
				count += 2;
			}

			if (c - 4 >= 0) {
				c -= 4;
				count += 4;
			}

		}
		System.out.println(count);
	}

}


public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scanner=new Scanner(System.in);
        int lemon = scanner.nextInt();
        int apple = scanner.nextInt();
        int pear = scanner.nextInt();

         int result=0;

        for(int i=lemon;i>0;i--){
             if(2*i<=apple&&4*i<=pear){
                result=i+(2*i)+(4*i);
                System.out.println(result+"");
                return;
            }

        }

    }


import java.util.*;
public class A746
{
    public static void main(String...arg)

    {
        int i,j,x,y,z,c=0;
        Scanner sc=new Scanner(System.in);
        x=sc.nextint();
        y=sc.nextint();
        z=sc.nextint();
        for(i=x;i>=0;i--)
        {
            c=0;
            if(y/2/i==0)
            c=1;
            if(z/4/i==0)
            c=1;
            if(c==0&&i!=0)
            {
                System.out.println(7*i);
                break;
            }
            if(i==0)
            {
                System.out.println("0");
            }
        }
    }
}


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.TreeMap;
public class Main {
	public static Scanner in=new Scanner(System.in);
	public static int num;
	public static int time[][]=new int[25][61];
	public static void main(String[] args){
		int a;
		int ta;
		int b;
		int tb;
		String s=in.nextLine();
		int z=0;
		int count=0;
		while(s.charAt(z)!=' ')z++;
		a=Integer.parseInt(s.substring(0, z));
		ta=Integer.parseInt(s.substring(z+1, s.length()));
		s=in.nextLine();
		z=0;
		while(s.charAt(z)!=' ')z++;
		b=Integer.parseInt(s.substring(0, z));
		tb=Integer.parseInt(s.substring(z+1, s.length()));
		s=in.nextLine();
		int starth=Integer.parseInt(s.substring(0, 2));
		int startm=Integer.parseInt(s.substring(3, 5));
		int hs=starth*60+startm;
		int he=hs+ta;
		int j=b;
		for(int i=300;i<24*60;i++){
			if(j==b){
				if(i>=(hs-tb)&&i<he){
					count++;
				}
				j=1;
			}
			else{
				j++;
			}
		}
		System.out.println(count);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int a = nextInt();
		int ta = nextInt();
		int b = nextInt();
		int tb = nextInt();
		String[]s = next().split(":");
		int h1 = Integer.parseInt(s[0]);
		int m1 = Integer.parseInt(s[1]);
		int h2 = h1;
		int m2 = m1 + ta;
		h2 += m2 / 60;
		m2 %= 60;
		int ans = 0;
		int H1 = 5, M1 = 0;
		while (true) {
			int H2 = H1;
			int M2 = M1;
			M2 += tb;
			H2 += M2 / 60;
			M2 %= 60;
			if (H1 > 10000)
				break;
			if (h1 < H2 || h1==H2 && m1 < M2) {
				if (H1 < h2 || H1==h2 && M1 < m2) {
					ans++;
				}
			}
			M1 += b;
			H1 += M1 / 60;
			M1 %= 60;
		}
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Bus {

    private static Scanner in;
    private static Output out;
    static boolean isFile = false;

    public static void solve() throws Exception {

        int t1 = in.nextInt();
        int s1 = in.nextInt();

        int t2 = in.nextInt();
        int s2 = in.nextInt();
        String[] startFirst = in.nextLine().split(":");

        int totalEnd = 24 * 60;
        int semenStart = Integer.parseInt(startFirst[0]) * 60 + Integer.parseInt(startFirst[1]);
        int startBus = 5 * 60;

        B a = new B(semenStart, semenStart + s1);

        List<B> bs = new ArrayList<>();
        int currentTime = startBus;
        bs.add(new B(currentTime, currentTime + s2));
        currentTime += t2;
        while (currentTime <= totalEnd) {
            bs.add(new B(currentTime, currentTime + s2));
            currentTime += t2;
        }

        int counter = 0;
        for (int i = 0; i < bs.size(); i++) {
            B b = bs.get(i);
            if (b.start >= a.end) {
                continue;
            }
            if (b.end <= a.start) {
                continue;
            }
            counter++;
//            if (b.start < a.end) {
//
//                continue;
//            }

        }

        out.println(counter);
    }

    private static class B {
        public int start;
        public int end;

        public B(int start, int end) {
            this.start = start;
            this.end = end;
        }

        @Override
        public String toString() {
            return "B{" +
                    "start=" + start +
                    ", end=" + end +
                    '}';
        }
    }

    static Exception exception;

    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    initReaderWriter();
                    solve();
                    out.close();
                } catch (Exception ex) {
                    exception = ex;
                }
            }
        }, "", 1 << 26);
        thread.start();
        thread.join();

        if (exception != null) {
            throw exception;
        }
    }

    private static void initReaderWriter() throws Exception {
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

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

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

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

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

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

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }

    private static void printMemory() {
        Runtime runtime = Runtime.getRuntime();

        long maxMemory = runtime.maxMemory();
        long allocatedMemory = runtime.totalMemory();
        long freeMemory = runtime.freeMemory();

        long div = 1L * 1024 * 1024;
        // long div = 1L ;

        System.out.println("used memory[mgb]: " + (runtime.totalMemory() - runtime.freeMemory()) / div);

        System.out.println();
    }

    static long appCurrentTime = System.currentTimeMillis();
    static long appCurrentTimeNano = System.nanoTime();

    private static void printCurrentTime() {
        out.flush();
        System.out.println("Time: " + (System.currentTimeMillis() - appCurrentTime));
        System.out.println("Time Nano: " + (System.nanoTime() - appCurrentTimeNano));
    }
}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author J
 */
public class code4 {
    public static void main(String[] args){
        InputScanner sc = new InputScanner();

        int[] xSet = new int[8];
        int[] ySet = new int[8];

        ArrayList<Integer> xSide = new ArrayList();
        ArrayList<Integer> ySide = new ArrayList();

        for(int i = 0 ; i < 8 ; i++){

            String line = sc.nextLine();
            String[] chars = line.split(" ");
            int x = Integer.parseInt(chars[0]);
            int y = Integer.parseInt(chars[1]);
            xSet[i] = x;
            ySet[i] = y;
            if(!xSide.contains(x)){

                xSide.add(x);

            }
            if(!ySide.contains(y)){

                ySide.add(y);

            }
            if(ySide.size() > 3 || xSide.size() > 3){

                System.out.println("ugly");
                return;
            }
        }
        Collections.sort(xSide);
        Collections.sort(ySide);

        for(int i = 0 ; i < 8 ; i++){

            if(xSet[i] == xSide.get(1) && ySet[i] == ySide.get(1)){

                System.out.println("ugly");
                return;

            }

        }
        System.out.println("respectable");
    }
    static class InputScanner {

        BufferedReader br;
        StringTokenizer st;

        public InputScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;

public class susbus{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  String s = sc.next();
  int count=0;
  int remove=0;
  for (int i=0;i<s.length();i++){
   if (s.charAT(i) == 'x'){
    count++;
   }
   else{
    if (count>=2){
     remove+=count-2;
    }
    count=0;
   }
  }
  System.out.println(remove);
 }
}


import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{
    static String s;
    static int len;
    static BigInteger ten = new BigInteger("10");
    static BigInteger nine = new BigInteger("9");
    static boolean []occ = new boolean [100005];
    static int letterEnc;

    static BigInteger solve( int i )
    {
        if( i == len )
            return new BigInteger("1");

        char c = s.charAt(i);

        if( c >= '0' && c <= '9'  )
            return solve(i+1);

        if( c == '?' )
        {
            if( i != 0 )
                return solve(i+1).multiply(ten);
            return solve(i+1).multiply(nine);
        }

        if( i != 0 )
        {
            if( occ[c] )
                return solve(i+1);
            occ[c] = true;
            letterEnc++;
            return solve(i+1).multiply(new BigInteger(String.format("%d",Math.max( 1 , 11 - letterEnc ))));

        }

        letterEnc = 1;
        occ[c] = true;
        return solve(i+1).multiply(nine);
    }

    public static void main( String[] args ) throws FileNotFoundException
    {
        String s = new Scanner(System.in).nextLine();
//        s = new Scanner(new File("c:\\a.txt")).nextLine();

        len = s.length();

        for( int i = 0 ; i < len ; i++ )
            occ[i] = false;

        letterEnc = 0;

        System.out.println(solve(0));
    }
}


import static java.lang.Integer.parseInt;
import static java.lang.Double.parseDouble;
import static java.lang.Long.parseLong;
import static java.lang.Math.*;

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

public class Main {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer stk;
	void Do() throws IOException
	{
		System.setIn(new FileInputStream(new File("input.txt")));
		in=new BufferedReader(new InputStreamReader(System.in));
		out=new PrintWriter(new OutputStreamWriter(System.out));
		solve();
		in.close();
		out.close();
	}
	private void solve() throws IOException{
		String s=next();
		boolean[] zimu=new boolean[26];
		int zimucnt=10;
		BigInteger ans=BigInteger.ONE;
		for(int i=0;i<s.length();i++)
		{
			char c=s.charAt(i);
			if(c=='?')
			{
				if(i==0) ans=ans.multiply(new BigInteger("9"));
				else ans=ans.multiply(new BigInteger("10"));
			}
			else if(c>='A' && !zimu[c-'A'])
			{
				zimu[c-'A']=true;
				if(zimucnt==0)
				{
					ans=BigInteger.ZERO;
					break;
				}
				if(i==0) ans=ans.multiply(new BigInteger("9"));
				else ans=ans.multiply(new BigInteger(""+zimucnt));
				zimucnt--;
			}
		}
		System.out.println(ans);
	}
	String next() throws IOException
	{
		while(stk==null || !stk.hasMoreTokens())
			stk=new StringTokenizer(in.readLine());
		return stk.nextToken();
	}
	int nextInt() throws IOException
	{
		return parseInt(next());
	}
	long nextLong() throws IOException
	{
		return parseLong(next());
	}
	double nextDouble() throws IOException
	{
		return parseDouble(next());
	}
	public static void main(String[] args) throws IOException{
		new Main().Do();
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    static Scanner in = new Scanner(System.in);
    static String cad = in.next();
    static int l = cad.length();
    static BigInteger res = new BigInteger("1");
    static int arr[] = new int[10];
    static int cont = 0;
    static int start = 10;
    public static void main(String[] args) {
        for(int i = 1; i < l; i++){
            if(cad.charAt(i) == '?')
                res = res.multiply(new BigInteger("10"));
            else{
                if(cad.charAt(i) > '9')
                    arr[cad.charAt(i) - 'A']++;
            }
        }
        if(cad.charAt(0) > '9')
            arr[cad.charAt(0) - 'A']++;
        for(int i = 0; i < 10; i++)
            if(arr[i] > 0) cont++;
        if(cad.charAt(0) == '?'){
            res = res.multiply(new BigInteger("9"));
        }
        else{
            if(cad.charAt(0) >= 'A'){
                start--;
                cont--;
                res = res.multiply(new BigInteger("9"));
            }
        }
        while(cont > 0){
            res = res.multiply(new BigInteger(Integer.toString(start)));
            start--;
            cont--;
        }
        System.out.println(res);
    }
}


import java.util.Scanner;
public class A{
     public static void main(String args[])  {
       Scanner in = new Scanner(System.in);
       int n = in.nextInt();
       int m = in.nextInt();
       int r = in.nextInt();
       int min;
       int a;
       for (int i =0; i<n;i++){
              a = in.nextInt();
              if (i==0) min=a;
              else if (a<min) min = a;
       }
       int max;
       for (int i=0; i<m;i++){
              a=in.nextInt();
              if (i==0)max =a;
              else if (a>max)max =a;
       }
       int ko=r/min;
       int r1=ko*max + r%min;
       if (r>= r1) System.out.println(r);
       else System.out.println(r1);
       }
}


import javax.annotation.processing.SupportedSourceVersion;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.management.BufferPoolMXBean;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.Scanner;
public class Chess {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int[] k = new int[3];
        for(int i = 0; i < 3; i++)
        {
            k[i] = input.nextInt();
        }
        int[] m = new int[k[0]];
        for(int i = 0; i<k[0]; i++)
        {
            m[i] = input.nextInt();
        }
        int[] n = new int[k[1]];
        for(int i = 0; i<k[1]; i++)
        {
            n[i] = input.nextInt();
        }
        Arrays.sort(m);
        Arrays.sort(n);
        if(m[0] > n[k[1] -1])
        {
            System.out.println(k[2]);
        }
        else
        {
            int l;
            l = (int) Math.floor(k[2] / m[0]);
            l = l * n[k[1] - 1] + (k[2] - l * m[0]);
            System.out.println(l);
        }
    }


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;

public class ForcesC {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	static FastReader sc = new FastReader();
    static List<Integer>[] edge ;
	public static void main(String[] args) {

		 int n = sc.nextInt();
	     int m = sc.nextInt();
	     int r = sc.nextInt();
	     int minn = Integer.MAX_VALUE,maxm = Integer.MIN_VALUE;
	     for(int i=0;i<n;++i) {
	    	 int temp = sc.nextInt();
	    	 minn = Math.min(minn, temp);
	     }
	     int buy = r/minn;
	     for(int i=0;i<n;++i) {
	    	 int temp = sc.nextInt();
	    	 maxm = Math.max(maxm, temp);
	     }
	     int sell = maxm*buy+r%minn;
	     out.println(Math.max(sell, r));
	      out.close();
	    }

	private static void add(TreeMap<Integer, Integer> map, int i) {
		// TODO Auto-generated method stub
		if(map.containsKey(i)) map.put(i, map.get(i)+1);
		else map.put(i, 1);

	}
	private static void delete(TreeMap<Integer, Integer> map, int i) {
		if(map.containsKey(i)) {
			if(map.get(i) == 1) map.remove(i);
			else map.put(i, map.get(i)-1);
		}

	}
	}


public class VasyaAndChess
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%2 != 0)
			System.out.println("black");
		else
		{
			System.out.println("white");
			System.out.println(1 + " " + 2);
		}
		sc.close();
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solve7 {

    public static void main(String[] args) throws IOException {
        PrintWriter pw = new PrintWriter(System.out);
        new Solve7().solve(pw);
        pw.flush();
        pw.close();
    }

    public void solve(PrintWriter pw) throws IOException {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        String s = sc.next();
        int k = 0;
        for (char i = 'z'; i > 'a'; i--) {
            n = s.length();
            for (int j = 0; j < n; j++) {
                StringBuilder sb = new StringBuilder(s);
                for (int l = 0; l < sb.length(); l++) {
                    if (sb.charAt(l) == i) {
                        if (l == 0 && l + 1 < sb.length() && sb.charAt(l + 1) == i - 1) {
                            sb.deleteCharAt(l);
                            ++k;
                            break;
                        } else if (l == sb.length() - 1 && sb.length() > 1 && sb.charAt(l - 1) == i - 1) {
                            sb.deleteCharAt(l);
                            ++k;
                            break;
                        } else {
                            if (sb.charAt(l - 1) == i - 1 || sb.charAt(l + 1) == i - 1) {
                                sb.deleteCharAt(l);
                                ++k;
                                break;
                            }
                        }
                    }
                }
                s = sb.toString();
            }
        }
        pw.println(k);
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
            }
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            }
            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() {
            try {
                return br.readLine();
            } catch (Exception e) {
            }
            return null;
        }

        public boolean hasNext() throws IOException {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            String s = br.readLine();
            if (s == null || s.isEmpty()) {
                return false;
            }
            st = new StringTokenizer(s);
            return true;
        }
    }
}


import java.util.*;
import java.io.*;
public class shell
{
    public static void main(String args[]) throws java.lang.Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int x=Integer.parseInt(br.readLine());
        if(x<0||x>2)
        System.exit(0);
        int arr[]=new int[3];
        arr[x]=1;
        int temp=0;
        while(n!=0)
        {
            if(n%2==0)
            {
               temp=arr[1];
               arr[1]=arr[2];
               arr[2]=temp;
            }
            else
            {
                temp=arr[1];
               arr[1]=arr[0];
               arr[0]=temp;
            }
            n=n-1;
        }
        for(int i=0;i<3;i++)
        {
            if(arr[i]==1)
            System.out.println(i);
        }
    }
}


import java.util.Scanner;

public class Contests {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int x = in.nextInt();
		int[][] matrix = new int[3][n];
		matrix[0][0] = 0;
		matrix[1][0] = 1;
		matrix[2][0] = 2;
		if (x == 0 && n % 2 == 1) {
			n = n % 5;
			if (n == 1)
				x = 1;
			else if (n == 2)
				x = 2;
			else if (n == 3)
				x = 2;
			else if (n == 4)
				x = 1;

		} else if (x == 1 && n % 2 == 1) {
			n = n % 6;
			if (n == 1)
				x = 0;
			else if (n == 2)
				x = 0;
			else if (n == 3)
				x = 1;
			else if (n == 4)
				x = 2;
			else if (n == 5)
				x = 2;
		} else if (x == 2 && n % 2 == 1) {
			n = n % 6;
			if (n == 2)
				x = 1;
			else if (n == 3)
				x = 0;
			else if (n == 4)
				x = 0;
			else if (n == 5)
				x = 1;

		} else if (x == 0 && n % 2 == 0) {
			n = n % 6;
			if (n == 2)
				x = 1;
			else if (n == 3)
				x = 2;
			else if (n == 4)
				x = 2;
			else if (n == 5)
				x = 1;

		} else if (x == 1 && n % 2 == 0) {
			n = n % 6;
			if (n == 1)
				x = 2;
			else if (n == 2)
				x = 2;
			else if (n == 3)
				x = 1;
			else if (n == 4)
				x = 0;
			else if (n == 5)
				x = 0;
		} else if (x == 2 && n % 2 == 0) {
			n = n % 5;
			if (n == 1)
				x = 1;
			else if (n == 2)
				x = 0;
			else if (n == 3)
				x = 0;
			else if (n == 4)
				x = 1;
		}
		System.out.println(x);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	static int n;
	static ArrayList<Integer> bad [][][];
	static char a [][], b [];
	static int res [];
	static int tmp [];
	static boolean visited[];

	static boolean ok (int node, int col) {
		visited[node] = true;
		tmp[node] = col;
		boolean can = true;

		for (int child : bad[node][col][0]) {
			if (visited[child]) {
				can &= tmp[child] == 1;
			}
			else {
				can &= ok (child, 1);
			}
		}
		for (int child : bad[node][col][1]) {
			if (visited[child]) {
				can &= tmp[child] == 0;
			}
			else {
				can &= ok (child, 0);
			}
		}
		visited[node] = false;
		return can;
	}

	static void fill (int node, int col) {
		visited[node] = true;
		res[node] = col;

		for (int child : bad[node][col][0]) {
			if (!visited[child]) {
				fill(child, 1);
			}
		}

		for (int child : bad[node][col][1]) {
			if (!visited[child]) {
				fill(child, 0);
			}
		}
	}
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		bad = new ArrayList[n][2][2];
		visited = new boolean[n];
		res = new int[n];
		a = new char[n][];
		b = new char[n];
		tmp = new int[n];
		for (int i = 0; i < n; i++) {
			bad[i][0][0] = new ArrayList<>();
			bad[i][0][1] = new ArrayList<>();
			bad[i][1][0] = new ArrayList<>();
			bad[i][1][1] = new ArrayList<>();
			a [i] = sc.next().toCharArray();
			b [i] = sc.next().charAt(0);
		}

		for (int i = 0; i < n; i++) {
			String f = a[i][0] + "" + a[i][1] + "" + a[i][2];
			String s = a[i][0] + "" + a[i][1] + "" + b[i];
			for (int j = 0; j < n; j++) {
				if (i != j) {
					String ff = a[j][0] + "" + a[j][1] + "" + a[j][2];
					String ss = a[j][0] + "" + a[j][1] + "" + b[j];
					if (f.equals(ff)) {
						bad[i][0][0].add(j);
						bad[i][1][0].add(j);
					}
					if(s.equals(ss)) bad[i][1][1].add(j);
					if (f.equals(ss)) bad[i][0][1].add(j);
					if (s.equals(ff)) bad[i][1][0].add(j);
				}
			}
		}

		boolean can = true;
		for (int i = 0; i < n; i++) {
			if (!visited[i]) {
				if (!ok(i, 0)) {
					if (!ok(i, 1)) {
						can = false;
						break;
					}
					else fill (i, 1);
				}
				else fill(i, 0);
			}
		}

		if (can) {
			out.println("YES");
			for (int i = 0; i < n; i++)
				if (res[i] == 0) out.println(a[i][0] + "" + a[i][1] + "" + a[i][2]);
				else out.println(a[i][0] + "" + a[i][1] + "" + b[i]);
		}
		else out.println("NO");
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

		public boolean nextEmpty() throws IOException
		{
			String s = nextLine();
			st = new StringTokenizer(s);
			return s.isEmpty();
		}
	}
}


import java.util.Scanner;

public class Main {
	public static void main(String arg[])
	{
		Scanner scanf=new Scanner(System.in);
		int n,x,t = 0;
		int[] num=new int[4];
		while(scanf.hasNext())
		{
			n=scanf.nextInt();
			for(int z=0;z<4;z++)
			{
				num[z]=0;
			}
			x=scanf.nextInt();
			num[x]=1;
			n=n%6;
			for(int z=n;z>0;z--)
			{
				if(z%2==0)
				{
					t=num[1];
					num[1]=num[2];
					num[2]=t;
				}
				else
				{
					t=num[0];
					num[0]=num[1];
					num[1]=t;
				}
			}
			for(int z=0;z<3;z++)
			{
				if(num[z]==1)
					t=z;
			}
			System.out.println(t);
			scanf.close();
		}
	}
}


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

public class Main
{
	static final boolean _DEBUG = false;

	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner(BufferedReader _br) {
			br = _br;
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
					return "";
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	static MyScanner   scan;
	static PrintWriter out;

	static int debugCount = 0;
	static void debug(String msg) {
		if (_DEBUG && debugCount < 200) {
			out.println(msg);
			out.flush();
			debugCount++;
		}
	}

    public static void main (String args[]) throws IOException {
//    	scan = new MyScanner(new BufferedReader(new FileReader("test.in")));
    	scan = new MyScanner(new BufferedReader(new InputStreamReader(System.in)));
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        Main inst = new Main();
        inst.execute();
        out.close();
    }

    int N, M, pow;
    int[] counts;
    int[][][] dp;

    void execute() {
    	N = scan.nextInt();
    	M = scan.nextInt();
    	if (N < M) {
    		int temp = N;
    		N = M;
    		M = temp;
    	}
    	pow = 1<<M;
    	counts = new int[pow];
    	dp = new int[N][pow][pow];
    	for (int[][] i : dp) {
    		for (int[] j : i) {
    			Arrays.fill(j, -1);
    		}
    	}
    	for (int i = 0; i < pow; i++) {
    		counts[i] = Integer.bitCount(i);
    		if (((i|(i<<1)|(i>>1))&(pow-1))==(pow-1)) {
        		dp[0][i][0] = counts[i];
    		}
    	}
    	int spiders = Integer.MAX_VALUE;
    	for (int y = 0; y < N-1; y++) {
    		for (int i = 0; i < pow; i++) {
    			for (int j = 0; j < pow; j++) {
    				if (dp[y][i][j] == -1) {
    					continue;
    				}
    				for (int k = 0; k < pow; k++) {
    					if (((i|(i<<1)|(i>>1)|j|k)&(pow-1))==(pow-1)) {
    						int value = dp[y][i][j] + counts[k];
    						if (dp[y+1][k][i] == -1 || dp[y+1][k][i] > value) {
    							dp[y+1][k][i] = value;
    						}
    					}
    				}
    			}
    		}
    	}
//    	System.out.println(Arrays.deepToString(dp));
    	for (int i = 0; i < pow; i++) {
    		for (int j = 0; j < pow; j++) {
    			if (dp[N-1][i][j] != -1 && ((i|(i<<1)|(i>>1)|j)&(pow-1))==(pow-1)) {
    				spiders = Math.min(spiders, dp[N-1][i][j]);
    			}
    		}
    	}
    	out.println((N*M)-spiders);
    }
}


import java.util.Scanner;

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

        int n = r.nextInt();
        int m = r.nextInt(import java.util.Arrays;
import java.util.Scanner;

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

        int n = r.nextInt();
        int m = r.nextInt();

        if(n > m){int t = n; n = m; m = t;}

        dp = new int[m+1][1 << 7][1 << 7];
        for(int[][] i : dp)
            for(int[] j : i)
                Arrays.fill(j, -1);
        int min = go(m, 0, (1<<n) -1, n, m);

        System.out.println(n * m - min);
    }
    static int[][][] dp;
    private static int go(int rem, int prev, int need, int n, int m) {
//      for(int i = rem; i < m; i++)
//          System.out.print(" ");
//      System.out.println(rem + ": " + prev +","+need);
        if(rem == 0)return prev == 0?0:1 << 20;
        if(dp[rem][prev][need] != -1)return dp[rem][prev][need];

        int min = 1 << 20;
        for(int now = 0; now < 1 << n; now++){
            if((~now & prev) != 0)continue;

            int after = need & ~(now) & ~(now << 1) & ~(now >> 1);
            int next = ~(now) & ((1 << n)-1);
            int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);
            min = Math.min(min, current);
        }
        return dp[rem][prev][need] = min;
    }
}
);

        if(n > m){int t = n; n = m; m = t;}

        dp = new int[m+1][1 << 7][1 << 7];
        int min = go(m, 0, (1<<n) -1, n, m);

        System.out.println(n * m - min);
    }
    static int[][][] dp;
    private static int go(int rem, int prev, int need, int n, int m) {
//      for(int i = rem; i < m; i++)
//          System.out.print(" ");
//      System.out.println(rem + ": " + prev +","+need);
        if(rem == 0)return prev == 0?0:1 << 20;
        if(dp[rem][prev][need] != -1)return dp[rem][prev][need];

        int min = 1 << 20;
        for(int now = 0; now < 1 << n; now++){
            if((~now & prev) != 0)continue;

            int after = need & ~(now) & ~(now << 1) & ~(now >> 1);
            int next = ~(now) & ((1 << n)-1);

            int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);
            min = Math.min(min, current);
        }
        return dp[rem][prev][need] = min;
    }
}