import com.sun.org.apache.xml.internal.security.utils.XalanXPathAPI;

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

/**
 * @author gamezovladislav
 */

public class TaskD {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solve solve = new Solve(in, out);
        solve.solve();
        out.close();
    }

    private static class Solve {

        private final InputReader in;
        private final PrintWriter out;

        public Solve(InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        char[][] c = new char[2][];

        public void solve() {
            c[0] = in.next().toCharArray();
            c[1] = in.next().toCharArray();
            int ans = 0;

            int n = c[0].length;

            for (int i = 0; i + 1 < n; i++) {
                int ti = type(i);
                int ti1 =  type(i+1);
                if (ti != 0 && ti1 != 0) continue;
                if (ti == 3 || ti1 == 3) continue;
                ans++;
                fill(i, ti, ti1);
            }

            out.print(ans);
        }

        private void fill(int i, int ti, int ti1) {
            if (ti == 0 && ti1 == 1) {
                c[0][i] = 'X';
                c[1][i] = 'X';
                c[0][i + 1] = 'X';
                c[1][i + 1] = c[1][i + 1];
            }
            if (ti == 0 && ti1 == 2) {
                c[0][i] = 'X';
                c[1][i] = 'X';
                c[0][i + 1] = c[0][i + 1];
                c[1][i + 1] = 'X';
            }
            if (ti == 1 && ti1 == 0) {
                c[0][i+1] = 'X';
                c[1][i+1] = 'X';
                c[0][i] = 'X';
                c[1][i] = c[1][i];
            }
            if (ti == 2 && ti1 == 0) {
                c[0][i+1] = 'X';
                c[1][i+1] = 'X';
                c[0][i] = c[0][i];
                c[1][i] = 'X';
            }
            if (ti == 0 && ti1 == 0) {
                c[0][i] = 'X';
                c[1][i] = 'X';
                c[0][i + 1] = 'X';
                c[1][i + 1] = c[1][i + 1];
            }
        }

        private int type(int i) {
            int ret = 0;
            if (c[0][i] == 'X') ret |= 1;
            if (c[1][i] == 'X') ret |= 2;
            return ret;
        }
    }

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

    static class D491 {
        long[] dp;
        char[][] arr;
        long dp2;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            String str = in.scanString();
            arr = new char[2][str.length()];
            arr[0] = str.toCharArray();
            arr[1] = in.scanString().toCharArray();
            dp = new long[110];
            dp2 = new long[105][105];
            for (long arr[] : dp2) {
                Arrays.fill(arr, -1);
            }
            Arrays.fill(dp, -1);
            dp[0] = 0;
            dp[1] = 0;
            dp[2] = 1;
            dp[3] = 2;
            for (int i = 4; i <= 100; i++) {
                dp[i] = Math.max(dp[i - 2] + 1, dp[i - 3] + 2);
            }
            out.println(findit(0, arr[0].length - 1));

        }

        long findit(int l, int r) {
            if (r - l + 1 < 2) return 0;
            if (dp2[l][r] != -1) return dp2[l][r];
            for (int i = l; i <= r; i++) {
                if (arr[0][i] == 'X' || arr[1][i] == 'X') {
                    if (arr[0][i] == 'X' && arr[1][i] == 'X') {
                        return findit(l, i - 1) + findit(i + 1, r);
                    } else {
                        if (arr[0][i] == 'X') {
                            return Math.max(findit(l, i - 2), findit(i + 2, r)) + 1;
                        } else {
                            return Math.max(findit(l, i - 2), findit(i + 2, r)) + 1;
                        }
                    }
                }
            }
            return dp2[l][r] = dp[r - l + 1];
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public String scanString() {
            int c = scan();
            while (isWhiteSpace(c)) c = scan();
            StringBuilder RESULT = new StringBuilder();
            do {
                RESULT.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return RESULT.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


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

public class Main {
	public static void main(String[] args) {
	    BigInteger t[] = new BigInteger[100000];
	    t[0] = BigInteger.valueOf(100);
	    for(int i=1; i<t.length; ++i) {
	        t[i] = t[i-1].multiply(BigInteger.valueOf(i));
	    }
		Scanner in = new Scanner(System.in);
		BigDecimal a = in.nextBigDecimal();
		BigDecimal b = in.nextBigDecimal();
		int c = in.nextInt();
		BigDecimal res = a.divide(b, 100000, BigDecimal.ROUND_HALF_UP);
		res = res.setScale(100000, BigDecimal.ROUND_HALF_UP);
		String s = res.toString();
		int idx = s.indexOf(".");
		s = s.substring(idx+1);
		char ch[] = s.toCharArray();
		int ans = -1;
		for(int i=0; i<ch.length-1; ++i) {
			if(ch[i]-'0' == c) {
				ans = i+1;
				ans += t[i].toStrong().length()*0;
				break;
			}
		}
		System.out.println(ans);
	}
}


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

public class Main {

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

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			tokenizer = null;
		}

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(System.in), 32765);
			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 char nextChar() {
			return next().charAt(0);
		}

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

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

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

		public int[] nextIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public Integer[] nextIntegerArr(int n) {
			Integer[] arr = new Integer[n];
			for (int i = 0; i < n; i++) {
				arr[i] = new Integer(this.nextInt());
			}
			return arr;
		}

		public int[][] next2DIntArr(int n, int m) {
			int[][] arr = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					arr[i][j] = this.nextInt();
				}
			}
			return arr;
		}

		public int[] nextSortedIntArr(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

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

		public long[] nextSortedLongArr(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			Arrays.sort(arr);
			return arr;
		}

		public char[] nextCharArr(int n) {
			char[] arr = new char[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextChar();
			}
			return arr;
		}
	}

	public static InputReader scn = new InputReader();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		// InputStream inputStream = System.in; // Useful when taking input other than
		// console eg file handling // check ctor of inputReader
		// To print in file use this:- out = new PrintWriter("destination of file")
		// including extension");

		int a = scn.nextInt(), b = scn.nextInt(), c = scn.nextInt();
		if (a % b == 0) {
			if (c == 0) {
				System.out.println(1);
			} else {
				System.out.println(-1);
			}
			return;
		}

		a = a % b;
		int pos = 0, div;
		while (pos < 10000) {
			while (a < b) {
				a *= 10;
				pos++;
			}
			div = a / b;
			a = a % b;
			if (div == c) {
				System.out.println(pos);
				return;
			}

			if(a == 0) {
				if(c == 0) {
					System.out.println(pos + 1);
				} else {
					System.out.println(-1);
				}
				return;
			}
		}

		System.out.println(-1);
	}


import java.io.*;

    import java.math.*;
    import java.util.*;
          public class Main1
           {
            private InputStream is;
            private PrintWriter out;
            static int MOD = (int)(1e9+7);
            ArrayList<Integer>[] amp;
            public static void main(String[] args) throws Exception
            {
                new Thread(null, new Runnable()
                {
                public void run()
                {
                    try {
         } catch (Exception e)
                    {
                        System.out.println(e);
                    }
                }
            }, "1", 1 << 26).start();
                new Main1().soln();
            }
            char ch[][];
            static ArrayList<Integer>[] g;
            static ArrayList<Integer> ar[];
            static long ok[];
            static int phi[]=new int[500005];
            void solve()
            {


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

public class Main {
	public static void main(String[] args) {
	    BigInteger t[] = new BigInteger[10000];
	    t[0] = BigInteger.valueOf(10);
	    for(int i=1; i<t.length; ++i) {
	        t[i] = t[i-1].multiply(BigInteger.valueOf(i);
	    }
		Scanner in = new Scanner(System.in);
		BigDecimal a = in.nextBigDecimal();
		BigDecimal b = in.nextBigDecimal();
		int c = in.nextInt();
		BigDecimal res = a.divide(b, 100000, BigDecimal.ROUND_HALF_UP);
		res = res.setScale(100000, BigDecimal.ROUND_HALF_UP);
		String s = res.toString();
		int idx = s.indexOf(".");
		s = s.substring(idx+1);
		char ch[] = s.toCharArray();
		int ans = -1;
		for(int i=0; i<ch.length-1; ++i) {
			if(ch[i]-'0' == c) {
				ans = i+1;
				ans += t[i].toString().length()*0;
				break;
			}
		}
		System.out.println(ans);
	}
}


public class Main {
    static long nCk(long n, long k) {
        if (n < k) {
            return 0;
        }
        if (k == 0) {
            return 1;
        }
        if (k == 1) {
            return n;
        }
        long x = n;
        for (int i = 1; i<k; i++) {
            x*= (n-i);
        }
        long y = 1;
        while (k > 0) {
            y *= k;
        }
        return x / y;
    }

    public static void main() {
        Scanner s new Scanner();
        int z = s.nextInt();
        long n = (long) z;
        System.out.println(6 * nCk(n - 3, 0) + 12 * nCk(n - 3, 1) + 8 * nCk(n - 3, 2) + 2 * nCk(n - 3, 3))

    }
}


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.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Minimum_Triangulation {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream in = System.in;
		OutputStream out = System.out;
		Scanner t = new Scanner(in);
		PrintWriter writ = new PrintWriter(out);
		int n = t.nextInt();
		long sum = 0;

		for (int i = 2; i < n; i++)
			sum += i * (i + 1);

		writ.println(sum);

		writ.close();
	}


public class T1140D {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int result = 0;
        for (int i = 2; i < n; ++i) {
            result += i * (i + 1);
        }
        System.out.println(result);
    }
}


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

public class Main {
    private static final String HelpStr = "What are you doing at the end of the world? Are you busy? Will you save us?";
    private static final String HelpStr1 = "What are you doing while sending \"What are you doing at the end of the world? Are you busy? Will you save us?\"? Are you busy? Will you send \"What are you doing at the end of the world? Are you busy? Will you save us?\"?";
    private static final Long[] arr1 = new Long[56];
    static {
        for (int i = 0; i < 56; i++) {
            arr1[i]=getNum(i);
            //System.out.println(arr1[i]);
        }
    }

    private static char getCharachter(int n,Long num){
        Long help = getHelpNum(n);
        if (n==0){
            return HelpStr.length()<num || num<1?'.':HelpStr.charAt(num.intValue()-1);
        }
        if (num<34){
            return HelpStr1.charAt(num.intValue()-1);
        }else{
            if (num-34<getHelpNum(n-1)){
                return getCharachter(n-1,num-34);
            }else{
                if (num-67<getHelpNum(n-1)){
                    return HelpStr1.charAt((int) (num-getHelpNum(n-1)+74));
                }else{
                    if ((num - 66)<getHelpNum(n-1)*2){
                        return getCharachter(n-1,num - (getHelpNum(n-1) + 66));
                    }else{
                        int aa = (int) (217 - (help-num));
                        return HelpStr1.length()<=aa || aa<0?'.':HelpStr1.charAt(aa);
                    }
                }
            }
        }

    }

    private static Long getHelpNum(int n){
        return n>55?Long.MAX_VALUE:arr1[n];
    }

    private static Long getNum(int n){
        return n>0?68+getNum(n-1)*2:75L;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] arr;
        Long a,b,k,p,countStrings=5L;
        arr = in.readLine().split(" ");
        countStrings = Long.valueOf(arr[0]);
        StringBuilder helpStr = new StringBuilder();
        String str1 = "What are you doing at the end of the world? Are you busy? Will you save us?";
        String str2="What are you doing while sending \"1\"? Are you busy? Will you send \"2\"?";

        Long[] arr1 = new Long[100];

        StringBuilder answer = new StringBuilder();
        for (int i = 0; i < countStrings; i++) {
            arr = in.readLine().split(" ");
            a = Long.valueOf(arr[0]);
            b = Long.valueOf(arr[1]);
            answer.append(getCharachter(a.intValue(),b));
        }

        System.out.println(answer.toString());
    }

}


import java.util.Scanner;

public class C896A {

    static final String xx = "What are you doing at the end of the world? Are you busy? Will you save us?";
    static final int lx = xx.length();

    static final String aa = "What are you doing while sending \"";
    static final int la = aa.length();
    static final String bb = "\"? Are you busy? Will you send \"";
    static final int lb = bb.length();
    static final String cc = "\"?";
    static final int lc = cc.length();

    static final int N = 100001;
    static final long[] len = new long[N];

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

        len[0] = lx;
        for (int i = 1; i < N; i++) {
            len[i] = 2 * len[i - 1] + la + lb + lc;
            if (len[i] >= 3000000000000000000L) {
                break;
            }
        }

        int q = scanner.nextInt();
        for (int i = 0; i < q; i++) {
            long n = scanner.nextLong();
            long k = scanner.nextLong();
            k--;
            if (len[n] > 0 && k > len[n]) {
                System.out.print('.');
            } else {
                solve(n, k);
            }
        }
    }

    public static void solve(long n, long k) {
        if (n == 0) {
            System.out.print(xx.charAt((int) k));
        } else if (len[(int) n] == 0) {
            solve(n - 1, k - la);
        } else {
            if (k < la) {
                System.out.print(aa.charAt((int) k));
            } else if (k < la + len[(int) (n - 1)]) {
                solve(n - 1, k - la);
            } else if (k < la + len[(int) (n - 1)] + lb) {
                System.out.print(bb.charAt((int) (k - la - len[(int) (n - 1)])));
            } else if (k < la + 2 * len[(int) (n - 1)] + lb) {
                solve(n - 1, k - la - len[(int) (n - 1)] - lb);
            } else {
                System.out.print(cc.charAt((int) (k - la - 2 * len[(int) (n - 1)] - lb)));
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

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

    static class TaskA {
        String f0 = "What are you doing at the end of the world? Are you busy? Will you save us?";
        String t1 = "What are you doing while sending \"";
        String t2 = "\"? Are you busy? Will you send \"";
        String t3 = "\"?";
        long len = new long[100001];

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            calclen();
            int q = in.nextInt();

            while (q > 0) {
                int n = in.nextInt();
                long k = in.nextLong();

                findchar(n, k - 1);
                q--;
            }
        }

        void findchar(int n, long k) {
            if (k >= len[n]) {
                System.out.print(".");
                return;

            } else if (n == 0) {
                System.out.print(f0.charAt((int) k));
                return;

            } else if (k < t1.length()) {
                System.out.print(t1.charAt((int) k));
                return;
            }
            k = k - t1.length();
            //System.out.println("k="+k+"n="+n);
            if (k <= len[n - 1]) {
                findchar(n - 1, k);
                return;
            }
            k = k - len[n - 1];
            if (k <= t2.length()) {
                System.out.print(t2.charAt((int) k));
                return;
            }
            k = k - t2.length();

            if (k <= len[n - 1]) {
                findchar(n - 1, k);
                return;
            }
            k = k - len[n - 1];
            if (k <= t3.length()) {
                System.out.print(t3.charAt((int) k));
                return;
            }

        }

        void calclen() {
            len[0] = f0.length();

            int i;
            for (i = 1; i <= 100000; i++) {
                len[i] = t1.length() + len[i - 1] + t2.length() + len[i - 1] + t3.length();
            }
        }

    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main implements Runnable {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C897 solver = new C897();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class C897 {
        String zero = new String("What are you doing at the end of the world? Are you busy? Will you save us?");

        Long len(int N) {
            if (N > 55) return null;
            return 75L * (long) Math.pow(2, N) + 68L * ((long) Math.pow(2, N) - 1);
        }

        char solve(int N, long ind) {
            if (N == 0)
                return zero.charAt((int) ind);
            Long len = len(N), len2 = len(N - 1);
            // What are you doing while sending "N - 1"? Are you busy? Will you send "N - 1"?
            if (ind < 34) {
                return "What are you doing while sending \"".charAt((int) ind);
            }
            if (len2 == null || ind < 34 + len2) {
                return solve(N - 1, ind - 34);
            }
            ind -= 34 + len2;
            // "? Are you busy? Will you send "N - 1"?
            if (ind < 32) {
                return "\"? Are you busy? Will you send \"".charAt((int) ind);
            }
            if (ind < 32 + len2) {
                return solve(N - 1, ind - 32);
            }
            ind -= 32 + len2;
            if (ind > 2)
                return '.';
            return "\"?".charAt((int) ind);
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {

            int N = s.nextInt();
            long ind = s.nextLong() - 1;

            Long len = len(N);
            if (len != null && ind >= len) {
                out.print(".");
                return;
            }

            out.print(solve(N, ind));

        }

    }

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

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

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

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

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

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

    }
}


//package fb1;

//package fb1;

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

public class MainA {

	public static int mod = 20000;
	public static long[] val;
	public static long[] arr;
	static long max = (long) 1e10 + 7;
	static long count=0;

	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long n=in.nextLong();
		int k=in.nextInt();
		//out.println(s);
		String s=Long.toString(n);
		int ans=s.length()-1count=0,rem=0,flag=0;

		if(s.length()<=k){}
		else
		{
		for(int i=s.length()-1;i>=0;i--)
		{
			if(s.charAt(i)=='0')
			{
				count++;
			}
			else
			{
				rem++;
			}
			if(count==k)
				{
				flag=1;
				break;

				}
		}
		}

		if(flag==1)
		out.println(rem);
		else
			out.println(ans);
		out.close();
	}

	static class Pairs implements Comparable<Pairs> {
		int x;
		int y;

		Pairs(int a, int b) {
			x = a;
			y = b;
		}

		@Override
		public int compareTo(Pairs o) {
			// TODO Auto-generated method stub
			if (x == o.x)
				return Integer.compare(y, o.y);
			else
				return Integer.compare(x, o.x);
		}

	}

	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static boolean isPal(String s) {
		for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {
			if (s.charAt(i) != s.charAt(j))
				return false;
		}
		return true;
	}

	public static String rev(String s) {
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}

	public static long gcd(long x, long y) {
		if (y == 0)
			return x;
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static int gcd(int x, int y) {
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static long gcdExtended(long a, long b, long[] x) {

		if (a == 0) {
			x[0] = 0;
			x[1] = 1;
			return b;
		}
		long[] y = new long[2];
		long gcd = gcdExtended(b % a, a, y);

		x[0] = y[1] - (b / a) * y[0];
		x[1] = y[0];

		return gcd;
	}

	public static int abs(int a, int b) {
		return (int) Math.abs(a - b);
	}

	public static long abs(long a, long b) {
		return (long) Math.abs(a - b);
	}

	public static int max(int a, int b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static int min(int a, int b) {
		if (a > b)
			return b;
		else
			return a;
	}

	public static long max(long a, long b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static long min(long a, long b) {
		if (a > b)
			return b;
		else
			return a;
	}

	public static long[][] mul(long a[][], long b[][]) {
		long c[][] = new long[2][2];
		c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];
		c[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];
		c[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];
		c[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];

		return c;
	}

	public static long[][] pow(long n[][], long p, long m) {
		long result[][] = new long[2][2];
		result[0][0] = 1;
		result[0][1] = 0;
		result[1][0] = 0;
		result[1][1] = 1;

		if (p == 0)
			return result;
		if (p == 1)
			return n;
		while (p != 0) {
			if (p % 2 == 1)
				result = mul(result, n);
			//System.out.println(result[0][0]);
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 2; j++) {
					if (result[i][j] >= m)
						result[i][j] %= m;
				}
			}

			p >>= 1;
			n = mul(n, n);
			// System.out.println(1+" "+n[0][0]+" "+n[0][1]+" "+n[1][0]+" "+n[1][1]);
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 2; j++) {
					if (n[i][j] >= m)
						n[i][j] %= m;
				}
			}
		}
		return result;
	}

	public static long pow(long n, long p) {
		long result = 1;
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		while (p != 0) {
			if (p % 2 == 1)
				result *= n;
			p >>= 1;
			n *= n;
		}
		return result;
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

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

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

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

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

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

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

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

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(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;
		}

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

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


import java.util.*;
public class codeforces {
public static void main (String[]args) {
	Scanner d=new Scanner (System.in);
	Scanner b=new Scanner (System.in);
	int []s= new int [2];
	for(int i=0;i<2;i++) {
		s[i]=a.nextInt();
	}
	int x=(int) Math.pow(10,s[1]);
	int y=s[0];
	int r=0;
	int f=s[1];
	if(y<x) {
		while(y>0) {
			if(y%10==0&y>=10) {
				r++;
				y/=10;
			}
			else {
				System.out.println(r);
			break;
			}
			}
	}
	else {
		while (f>0) {
			if(y%10==0) {
				f--;
				y/=10;
				}
				else {
					y/=10;
					r++;
				}
		}
	System.out.println(r);
	}
}
}


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

public class HW504 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        int m = sc.nextInt();
        String s = n.toString();
        char[] c = new char[n];
        c = s.toCharArray();
        int count =0;
        int out = 0;
        if (s.length()<m){
            System.out.println(s.length()-1);
        }else{
            for(int i =s.length()-1;i>=0;i-- ){
                if(c[i]=='0'){
                    count++;
                }else{
                    out++;
                }
                if (count==m){
                    break;
                }
            }
            System.out.println(out);
        }

    }
}


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

public class HW504 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        int m = sc.nextInt();
        char[] c = new char[n];
        c =  n.toString().toCharArray();
        int count =0;
        int out = 0;
        if (c.length<m){
            System.out.println(c.length-1);
        }else{
            for(int i =c.length-1;i>=0;i-- ){
                if(c[i]=='0'){
                    count++;
                }else{
                    out++;
                }
                if (count==m){
                    break;
                }
            }
            System.out.println(out);
        }

    }
}


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

public class Contest1646E
{
    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        String next() { // reads in the next string
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() { // reads in the next int
            return Integer.parseInt(next());
        }
        public long nextLong() { // reads in the next long
            return Long.parseLong(next());
        }
        public double nextDouble() { // reads in the next double
            return Double.parseDouble(next());
            }
        }
    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static long mod = 1000000007;
    public static void main(String[] args)
    {
    	int n = r.nextInt();
    	int m = r.nextInt();
    	int[] count = new int[n+5];
    	boolean[] seen = new boolean[n+5];
    	for (int i = 2; i <= n; i ++)
    	{
    		long j = i;
    		if (!seen[(int)j])
    		{
    			while (j <= n)
    			{
    				seen[(int)j] = true;
    				j *= i;
    				count[i] ++;
    			}
    		}
    	}
    	long ans = 1;
    	long[] hi = new long[22];
    	hi[0] = 0;
    	HashSet<Integer> set = new HashSet<Integer>();
    	for (int i = 1; i <= 20; i ++)
    	{
    		for (int j = i; j <= m*i; j += i)
    		{
    			set.add(j);
    		}
    		hi[i] = set.size();
    	}
    	for (int x = 2; x <= n; x ++)
    	{
    		ans += hi[count[x]];
    	}
    	pw.println(ans);
        pw.close();
    }
}


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

public class Main {
    private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    private StringTokenizer st;
    private final Long MOD = 1000000007L;
    private final String endl = "\n";

    boolean isConsonant(char c) {
        return !isVowel(c);
    }

    boolean isVowel(char c) {
        return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
    }

    // IO UTILS

    void log(Object... args) {
        if (!TESTING) return;
        for (Object s : args) System.out.print(s.toString() + " ");
        System.out.println();
    }

    String line() throws IOException {
        return in.readLine().trim();
    }

    StringTokenizer tokens() throws IOException {
        return new StringTokenizer(line());
    }

    long l(String s) {
        return Long.parseLong(s);
    }

    long rl() throws IOException {
        return l(line());
    }

    long[] rla(int n) throws IOException {
        long[] arr = new long[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            arr[i] = l(st.nextToken());
        return arr;
    }

    int i(String s) {
        return Integer.parseInt(s);
    }

    int ri() throws IOException {
        return i(line());
    }

    int[] ria(int n) throws IOException {
        int[] arr = new int[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            arr[i] = i(st.nextToken());
        return arr;
    }

    String rs() throws IOException {
        return line();
    }

    String[] rsa(int n) throws IOException {
        String[] s = new String[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            s[i] = st.nextToken();
        return s;
    }

    double d(String s) {
        return Double.parseDouble(s);
    }

    double rd() throws IOException {
        return d(line());
    }

    double[] rda(int n) throws IOException {
        double[] arr = new double[n];
        st = tokens();
        for (int i = 0; i < n; i++) {
            arr[i] = d(st.nextToken());
        }
        return arr;
    }
    // IO UTILS END

    // MATH UTILS

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long lcm(long a, long b) {
        long g = gcd(a, b);
        return (a / g) * b; // directly multiply a and b can overflow
    }

    public long modInv(long a, long MOD) {
        return new BigInteger(a + "").modPow(new BigInteger((MOD - 2) + ""), new BigInteger(MOD + "")).longValue();
    }

    public long modPro(long a, long b, long MOD) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

    private long factorialMod(int n, long MOD) {
        long pro = 1;
        for (long i = 1; i <= n; i++) {
            pro = pro * i;
            pro %= MOD;
        }
        return pro;
    }

    static void ruffleSort(int[] a) {
        // ruffle
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n), temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }
        Arrays.sort(a);
    }

    static void ruffleSort(long[] a) {
        // ruffle
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n);
            long temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }
        Arrays.sort(a);
    }

    boolean[] sieveOfEratosthenes(int n) {
        boolean[] prime = new boolean[n + 1];
        for (int i = 0; i < n; i++)
            prime[i] = true;
        prime[0] = false;
        prime[1] = false;
        for (int i = 4; i <= n; i += 2) {
            prime[i] = false;
        }
        for (int p = 3; p * p <= n; p += 2) {
            // If prime[p] is not changed, then it is a prime
            if (prime[p]) {
                // Update all multiples of p
                for (int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
        return prime;
    }

    // MATH UTILS END
    private final boolean TESTING = false;

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

    private void solve() throws Exception {
        int testCases = 1;
//        testCases = Integer.parseInt(in.readLine().trim());
        preProcess();
        for (int i = 1; i <= testCases; i++) {
            solveTestCase(i);
        }
        out.flush();
        out.close();
    }

    void preProcess() {

    }

    private void solveTestCase(int testCaseNumber) throws Exception {
        int[] arr = ria(2);
        int n = arr[0];
        int m = arr[1];
        int log = 0;
        int two = 2;
        while (true) {
            if (two > n)
                break;
            two *= 2;
            log++;
        }

//999439867182
        boolean set[] = new boolean[log * n + 1];
        long hash[] = new long[log + 1];
        int count = 0;
        for (int i = 1; i <= log; i++) {
            for (int j = 1; j <= m; j++) {
                if (!set[i*j]) {
                    set[i*j] = true;
                    count += 1;
                }
            }
            hash[i] = count;
        }
//        System.out.println(set + endl + Arrays.toString(hash));

        long ans = 0;
        boolean[] done = new boolean[n + 1];
        for (int i = 2; i <= n; i++) {
            if (!done[i]) {

                long pow = 1;
                done[i] = true;
                long temp = i;
                while (true) {
                    temp *= i;
                    if (temp > n)
                        break;
                    done[(int) temp] = true;
                    pow++;

                }
//								System.out.println( i+ " " + pow+ " " + hash[(int)pow]);
                ans += hash[(int) pow];

            }
        }

        out.write(ans + 1 + endl);

    }

}


//Utilities
import java.io.*;
import java.util.*;

public class a {
	static int t;
	static int n, m;
	static int log2n;
	static int[] precompute;
	static boolean[] vis, isBasePow;
	static long res;

	public static void main(String[] args) throws IOException {
		t = 1;
		while (t-- > 0) {
			n = in.iscan(); m = in.iscan();
			log2n = 0;
			while ((1 << (log2n + 1)) <= n) {
				log2n++;
			}
			vis = new boolean[m*log2n+1];
			precompute = new int[log2n+1];
			int cnt = 0;
			for (int i = 1; i <= log2n; i++) {
				for (int j = 1; j <= m; j++) {
					if (!vis[i*j]) {
						vis[i*j] = true;
						cnt++;
					}
				}
				precompute[i] = cnt;
			}
			res = 1;
			isBasePow = new boolean[n+1]; Arrays.fill(isBasePow, true);
			for (int i = 2; i <= n; i++) {
				if (isBasePow[i]) {
					int p = 1;
					for (long j = i * i; j <= n; j *= i, p++) {
						isBasePow[(int)j] = false;
					}
					res += precompute[p];
				}
			}
			out.println(res);
		}
		out.close();
	}

	static INPUT in = new INPUT(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	private static class INPUT {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

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

		public INPUT (String file) throws IOException {
			this.stream = new FileInputStream (file);
		}

		public int cscan () throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read (buf);
			}

			if (numChars == -1)
				return numChars;

			return buf[curChar++];
		}

		public int iscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			int res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

		public String sscan () throws IOException {
			int c = cscan ();

			while (space (c))
				c = cscan ();

			StringBuilder res = new StringBuilder ();

			do {
				res.appendCodePoint (c);
				c = cscan ();
			}
			while (!space (c));

			return res.toString ();
		}

		public double dscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			double res = 0;

			while (!space (c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * UTILITIES.fast_pow (10, iscan ());

				res *= 10;
				res += c - '0';
				c = cscan ();
			}

			if (c == '.') {
				c = cscan ();
				double m = 1;

				while (!space (c)) {
					if (c == 'e' || c == 'E')
						return res * UTILITIES.fast_pow (10, iscan ());

					m /= 10;
					res += (c - '0') * m;
					c = cscan ();
				}
			}

			return res * sgn;
		}

		public long lscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			long res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

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

	public static class UTILITIES {

		static final double EPS = 10e-6;

		public static void sort(int[] a, boolean increasing) {
			ArrayList<Integer> arr = new ArrayList<Integer>();
			int n = a.length;
			for (int i = 0; i < n; i++) {
				arr.add(a[i]);
			}
			Collections.sort(arr);
			for (int i = 0; i < n; i++) {
				if (increasing) {
					a[i] = arr.get(i);
				}
				else {
					a[i] = arr.get(n-1-i);
				}
			}
		}

		public static void sort(long[] a, boolean increasing) {
			ArrayList<Long> arr = new ArrayList<Long>();
			int n = a.length;
			for (int i = 0; i < n; i++) {
				arr.add(a[i]);
			}
			Collections.sort(arr);
			for (int i = 0; i < n; i++) {
				if (increasing) {
					a[i] = arr.get(i);
				}
				else {
					a[i] = arr.get(n-1-i);
				}
			}
		}

		public static void sort(double[] a, boolean increasing) {
			ArrayList<Double> arr = new ArrayList<Double>();
			int n = a.length;
			for (int i = 0; i < n; i++) {
				arr.add(a[i]);
			}
			Collections.sort(arr);
			for (int i = 0; i < n; i++) {
				if (increasing) {
					a[i] = arr.get(i);
				}
				else {
					a[i] = arr.get(n-1-i);
				}
			}
		}

		public static int lower_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] >= x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static int upper_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] > x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static void updateMap(HashMap<Integer, Integer> map, int key, int v) {
			if (!map.containsKey(key)) {
				map.put(key, v);
			}
			else {
				map.put(key, map.get(key) + v);
			}
			if (map.get(key) == 0) {
				map.remove(key);
			}
		}

		public static long gcd (long a, long b) {
			return b == 0 ? a : gcd (b, a % b);
		}

		public static long lcm (long a, long b) {
			return a * b / gcd (a, b);
		}

		public static long fast_pow_mod (long b, long x, int mod) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;

			return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
		}

		public static long fast_pow (long b, long x) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow (b * b, x / 2);

			return b * fast_pow (b * b, x / 2);
		}

		public static long choose (long n, long k) {
			k = Math.min (k, n - k);
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = val * (n - i) / (i + 1);

			return val;
		}

		public static long permute (int n, int k) {
			if (n < k) return 0;
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = (val * (n - i));

			return val;
		}

		// start of permutation and lower/upper bound template
		public static void nextPermutation(int[] nums) {
		    //find first decreasing digit
		    int mark = -1;
		    for (int i = nums.length - 1; i > 0; i--) {
		        if (nums[i] > nums[i - 1]) {
		            mark = i - 1;
		            break;
		        }
		    }

		    if (mark == -1) {
		        reverse(nums, 0, nums.length - 1);
		        return;
		    }

		    int idx = nums.length-1;
		    for (int i = nums.length-1; i >= mark+1; i--) {
		        if (nums[i] > nums[mark]) {
		            idx = i;
		            break;
		        }
		    }

		    swap(nums, mark, idx);

		    reverse(nums, mark + 1, nums.length - 1);
		}

		public static void swap(int[] nums, int i, int j) {
		    int t = nums[i];
		    nums[i] = nums[j];
		    nums[j] = t;
		}

		public static void reverse(int[] nums, int i, int j) {
		    while (i < j) {
		        swap(nums, i, j);
		        i++;
		        j--;
		    }
		}

		static int lower_bound (int[] arr, int hi, int cmp) {
			int low = 0, high = hi, mid = -1;
			while (low < high) {
				mid = (low + high) / 2;
				if (arr[mid] >= cmp) high = mid;
				else low = mid + 1;
			}
			return low;
		}

		static int upper_bound (int[] arr, int hi, int cmp) {
			int low = 0, high = hi, mid = -1;
			while (low < high) {
				mid = (low + high) / 2;
				if (arr[mid] > cmp) high = mid;
				else low = mid + 1;
			}
			return low;
		}
		// end of permutation and lower/upper bound template
	}
}


/*
I am dead inside
Do you like NCT, sKz, BTS?
5 4 3 2 1 Moonwalk
Imma knock it down like domino
Is this what you want? Is this what you want?
Let's ttalkbocky about that
 */
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1646E
{
    public static void main(String hi[]) throws Exception
    {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        //preprocess
        boolean[] seen = new boolean[20*(1<<20)];
        int[] dp = new int[20];
        dp[0] = M;
        for(int v=1; v <= M; v++)
            seen[v] = true;
        for(int i=1; i < 20; i++)
        {
            dp[i] = dp[i-1];
            for(int v=1; v <= M; v++)
                if(!seen[(i+1)*v])
                {
                    seen[(i+1)*v] = true;
                    dp[i]++;
                }
        }
        long res = 1L;
        boolean[] bad = new boolean[N+1];
        for(int v=2; v <= N; v++)
            if(!bad[v])
            {
                int curr = 0;
                int temp = v;
                while(temp*v <= N)
                {
                    curr++;
                    temp *= v;
                    bad[temp] = true;
                }
                res += dp[curr];
            }
        System.out.println(res);
    }
    public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
    {
        int[] arr = new int[N];
        st = new StringTokenizer(infile.readLine());
        for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
        return arr;
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Hello_2018 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        long l = in.nextInt();
        long[]data = new long[31];
        long total = 0;
        for(int i = 0; i < 31; i++){
            if(i < n){
                data[i] = in.nextInt();
            }else{
                data[i] = Long.MAX_VALUE;
            }
            if(i > 0){
                data[i] = Long.min(data[i], 2L*data[i - 1]);
            }
            if(((1L<<i) & l) != 0){
                total += data[i];
            }else if((1L << i) > L){
                total = Long.min(total, data[i]);
            }
        }

        out.println(total);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        solve();
    }

    private static void solve() throws IOException {
        int n = Reader.nextInt();
        int l = Reader.nextInt();
        long[][] prices = new long[n][2]; // 0: price, 1: liters
        for (int i = 0; i < n; i++) {
            prices[i][0] = Reader.nextLong();
            prices[i][1] = 1 << i;
        }

        Arrays.sort(prices, C_PartyLemonade::compare);
        System.out.println(go(l, prices));
    }

    private static long go(long liter, long[][] prices) {
        if (liter <= 0) return 0;
        long[] lastprice = prices[0];
        int i = 0;
        long cost = Long.MAX_VALUE;
        while (i < prices.length) {
            if (lastprice[1] < liter && compare(prices[i], lastprice) == 1) break;

            if (prices[i][1] < liter) {
                long num = liter / prices[i][1];
                long remain = liter % prices[i][1];
                cost = Math.min(cost, prices[i][0] * num + go(remain, prices));
            } else {
                cost = Math.min(cost, prices[i][0] + go(liter - prices[i][1], prices));
            }
            lastprice = prices[i];
            i++;
        }
        return cost;
    }

    private static int compare(long[] i1, long[] i2) {
        long p1 = i1[0] * i2[1];
        long p2 = i2[0] * i1[1];
        if (p1 > p2) return 1;
        if (p1 < p2) return -1;
        if (i1[1] > i2[1]) return -1;
        if (i1[1] < i2[1]) return 1;
        return 0;
    }

    private static class Reader {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /**
         * call this method to initialize reader for InputStream
         */
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /**
         * get next word
         */
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

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

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

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

}


// package codeforces1;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
import java.text.*;

public class Chello2018 {

	static InputReader in = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = i();
		PrintWriter out = new PrintWriter(System.out);
		while (t > 0) {
			int n = i();
			int l =i();
			int arr[] = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = i();
			}
			int pw[]=new int[31];
			int p=1;
			for(int i=0;i<31;i++) {
				pw[i]=p;
				p=p*2;
			}
			pair1 pa[]=new pair1[n];
			for(int i=0;i<n;i++) {
				pa[i]=new pair1(pw[i] ,(int) ((double)arr[i]/pw[i]), arr[i]);
			}
			Arrays.sort(pa, new Comparator<pair1>() {
				public int compare(pair1 p1, pair1 p2) {
					return p1.y - p2.y;
				}
			});
			long fans=100000000000000000L;
			long ans=0L;
			long tm=0L;
//			System.out.println(pa[3].x);
//			for(int i=0;i<n;i++) {
//				System.out.println(pa[i].x+" "+pa[i].y);
//			}
			for(int i=0;i<n;i++) {
				if(pa[i].x<=l) {
					tm=l/pa[i].x;
					ans=ans+(long)tm*pa[i].z;
					l=(int) (l-(long)tm*(pa[i].x));
					fans=Math.min(ans+pa[i].z, fans);
				}
				else {
					fans=Math.min(fans, ans+pa[i].z);
				}
				if(l<=0) {
					fans=Math.min(fans, ans);
				}
			}
			System.out.println(fans);

			out.println();

			t--;

		}
		out.close();

		//		long l=l();
		//		String s=s();     //	ONLY BEFORE SPACE IN STRING , ELSE USE BUFFER-READER

	}

	public static long pow(long a, long b) {
		long m = 1000000007;
		long result = 1;
		while (b > 0) {
			if (b % 2 != 0) {
				result = (result * a) % m;
				b--;
			}
			a = (a * a) % m;
			b /= 2;
		}
		return result % m;
	}

	public static long gcd(long a, long b) {
		if (a == 0) {
			return b;
		}
		return gcd(b % a, a);
	}

	public static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}

	public static long l() {
		String s = in.String();
		return Long.parseLong(s);
	}

	public static void pln(String value) {
		System.out.println(value);
	}

	public static int i() {
		return in.Int();
	}

	public static String s() {
		return in.String();
	}

}

class pair1 {
	int x, y,z;

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

class CompareValue {

	static void compare(pair arr[], int n) {
		Arrays.sort(arr, new Comparator<pair>() {
			public int compare(pair p1, pair p2) {
				return p1.y - p2.y;
			}
		});
	}
}

class CompareKey {
	static void compare(pair arr[], int n) {
		Arrays.sort(arr, new Comparator<pair>() {
			public int compare(pair p1, pair p2) {
				return p2.x - p1.x;
			}
		});
	}
}

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

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

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

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

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

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

class IOUtils {
	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.Int();
		return array;
	}
}

/**
 * TO SORT VIA TWO KEYS , HERE IT IS ACCORDING TO ASCENDING ORDER OF FIRST AND
 * DESC ORDER OF SECOND
 * LIST name-list
 * ARRAYLIST
 * COPY PASTE
 *
 * Collections.sort(list, (first,second) ->{
		    	if(first.con >second.con)
		    		return -1;
		    	else if(first.con<second.con)
		    		return 1;
		    	else {
		    		if(first.index >second.index)
		    			return 1;
		    		else
		    			return -1;
		    	}

		    });
 *
 */

/**
 *

  DECIMAL FORMATTER
Double k = in.readDouble();

System.out.println(k);
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(k));
out.printLine(k);
*
* */


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author fuqianran
 */
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 {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();

            int[] litters = new int[N + 1];
            int[] costs = new int[N + 1];

            for (int i = 1; i <= N; ++i) {
                costs[i] = in.nextInt();
            }

            for (int i = 1; i <= N; ++i) {
                litters[i] = 1 << (i - 1);
            }

            int[] dp = new int[L + 1];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;

            for (int l = 1; l <= L; ++l) {

                for (int type = 1; type <= N; ++type) {
                    if (l - litters[type] >= 0) {
                        dp[l] = Math.min(dp[l], dp[l - litters[type]] + costs[type]);
                    } else {
                        dp[l] = Math.min(dp[l], costs[type]);
                    }
                }
            }

            out.println(dp[L]);

        }

    }

    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 println(int i) {
            writer.println(i);
        }

    }

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

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

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

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

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

        }

    }
}


public class Probram3 {

	public static int get(long n) {
		int sum = 0;
		while(n != 0) {
			sum += n % 10;
			n = n / 10;
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//while(true){
			long n = scanner.nextLong();
			long s = scanner.nextLong();
//			long l = 1;
//			long r = Long.MAX_VALUE;
//			long index = 0;
//			while(l <= r) {
//				long mid = (l + r) / 2;
//				if(s > mid) {
//					l = mid + 1;
//				}else if(s < mid) {
//					r = mid - 1;
//				}else{
//					index = mid;
//					break;
//				}
//			}
//			System.out.println(index);
			long x = s / 9 ;
			long y = s % 9 ;
			long k;
			if(y == 0) {
				k = 9 + (x - 1) * 10;
			}else{
				k = 9 + x * 10;
			}
			//System.out.println(k);
			if((n - k) > 0) {
				System.out.println(n - k);
			}else{
				System.out.println("0");
			}
		//}
	}
}


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

public class Solution {

    public static int fun(long n)
    {
        int ans = 0;
        while(n>0)
        {
            ans += n%10;
            n /= 10;
        }
        return ans;
    }

        public static long mod = 1000000007;
     public static void main(String[] args) throws IOException{

//         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
         PrintWriter  pw = new PrintWriter(System.out);
         Scanner in = new Scanner(System.in);

        // for(int i=0; i<1000; i+=10)

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

         long ll = 0;
         long rl = (long)Math.pow(10, 18);
         long mid = 0;
         long ans = 0;
         long k = (long)Math.ceil((double)x/9);
         while(rl-ll>=0)
         {
             mid =  (rl + ll)/2;

            // pw.println((mid)+" "+k);

             if(mid==k)
             {
                // pw.print("--");
                 ans =  mid;
                 break;
             }
             else if(mid>k)
            {

                // ans = mid;
                 rl = mid-1;
             }
              else
             {
                 ll = mid+1;
             }
           //  pw.println((mid)+" "+k);

         }
         //pw.print(ans);
         pw.print(Math.max(n - ()10*ans+1, 0));

         pw.flush();
         pw.close();

       }
    }


import java.util.Scanner;

public class Ivan{

  public static boolean check(long s,long n){
    long big = 0;
    long u = s;
    while (s >= 1){
      big =big + s % 10;
      s = (s - big) / 10;
    }
    if (u - big > n){
      return true;
    }else return false;
  }

  public static long analyze(long n){
    return n/9;
  }
  public static long number(long x){
    return x*9;
  }

  public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      long s = scan.nextLong();
      long n = scan.nextLong();
      long r =0;
      for (long i = n;i<s+1;i++){
        if (check(i,n)){
          r=i;
          break;
        }else r = s+1;
      }
      System.out.print(s-r+1);
    }
  }
}


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

public class Ivan{

  public static boolean check(long s,long n){
    long big = 0;
    long u = s;
    while (s >= 1){
      big =big + s % 10;
      s = (s - big) / 10;
    }
    if (u - big > n){
      return true;
    }else return false;
  }

  public static long analyze(long n){
    return n/9;
  }
  public static long number(long x){
    return x*9;
  }

  public static void main(String args[]){
    try{
      File file = new File("in.inp");
      Scanner scan = new Scanner(System.in);
      long s = scan.nextLong();
      long n = scan.nextLong();
      long r =0;
      for (long i = n;i<s+1;i++){
        if (check(i,n)){
          r=i;
          break;
        }
      }
      System.out.print(s-r+1);
    }catch (FileNotFoundException e){
      System.err.println(e.getMessage());
    }
  }
}


import java.util.Scanner;

public class MikeandChocolateThieves {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int m = input.nextInt();
		int l = 1;
		int r = 8*m;
		while(l<r){
			int mid = (l+r)/2;
			if(get(mid)<m){
				l = mid+1;
			}
			else
				r = mid;

		}
		if(get(r)==m){
			System.out.println(r);
		}
		else{
			System.out.println(-1);
		}
	}

	private static int get(int n){
		int res=0;
		for(int i=2;i*i*i<=n;i++){
			res+=n/i/i/i;
		}
		return res;
	}

}


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

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

        int N = sc.nextInt();

        Vertex[] ver = new Vertex[N];
        for(int i = 0; i<N; i++) ver[i] = new Vertex();
        for(int i = 0, len = N-1; i<len; i++) ver[i].path.add(i+1);

        for(int i = 0; i<N; i++){
            int p = sc.nextInt();
            ver[i].path.add(p-1);
        }

        int[] lengths = new int[N];
        boolean[] visited = new boolean[N];
        Arrays.fill(lengths, 0);
        Arrays.fill(visited, false);
        lengths[0] = 0;
        visited[0] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(0);
        while(!q.isEmpty()){
            int cur = q.remove();
            int len = lengths[cur];
            for(int p : ver[cur].path){
                if(!visited[p]){
                    visited[p] = true;
                    lengths[p] = len+1;
                    q.add(p);
                }
            }
        }

        //StringBuilder sb = new StringBuilder();
        //sb.append(lengths[0]);
        for(int i = 0; i<N; i++){
            System.out.print(lengths[i] + " ");
        }
        //System.out.print(sb);
    }
}

class Vertex{
    ArrayList<Integer> path;
    Vertex(){
        path = new ArrayList<>();
    }
}


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

public class Codeforces {

	static MyScanner sc = new MyScanner();

	public static void computePaths(Vertex source) {

		source.minDistance = 0;
		PriorityQueue<Vertex> vertexQueue = new PriorityQueue<Vertex>();
		vertexQueue.add(source);

		while (!vertexQueue.isEmpty()) {

			Vertex u = vertexQueue.poll();

			for (Edge e: u.adjacencies) {

				Vertex tr = e.target;
				double weight = e.weight;

				double DistanceThroughU = u.minDistance + weight;

				if (DistanceThroughU < tr.minDistance) {
					vertexQueue.remove(tr);
					tr.minDistance = DistanceThroughU;
					tr.previous = u;
					vertexQueue.add(tr);
				}

			}

		}
	}

	public static List<Vertex> getShortestPathTo (Vertex target) {

		List<Vertex> path = new ArrayList<Vertex>();

		for (Vertex v= target ; v != null ; v = v.previous) {
			path.add(v);
		}

		Collections.reverse(path);

		return path;
	}

	public static void main(String[] args) {

		int n = sc.nextInt();
		Vertex [] arr = new Vertex [n];
		//List<Vertex> list = new ArrayList<Vertex>();

		int target;

		for (int i=0 ; i<n ; i++) {
			arr[i] = new Vertex ();
		}

		target = sc.nextInt() - 1;
		arr[0].adjacencies = new Edge[] {new Edge(arr[1],1), new Edge (arr[target],1)};

		for (int i=1 ; i<n-1 ; i++) {

			target = sc.nextInt() -1;
			arr[i].adjacencies = new Edge [] {new Edge(arr[i-1],1), new Edge(arr[i+1], 1) , new Edge(arr[target],1) };
		}

		target = sc.nextInt() - 1;
		arr[n-1].adjacencies = new Edge[] {new Edge(arr[n-2],1), new Edge (arr[target],1)};

		computePaths(arr[0]);

		for (int i=0 ; i<n ; i++) {
			//System.out.println(arr[i].adjacencies.toString());
			System.out.print((int)arr[i].minDistance + " ");
		}

	}

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

    }

}

class Vertex implements Comparable<Vertex> {

	//public final String name;
	public Edge [] adjacencies;
	public double minDistance = Double.POSITIVE_INFINITY;
	public Vertex previous;

	public int compareTo(Vertex other) {
		return Double.compare(minDistance, other.minDistance);
	}

}

class Edge {

	public Vertex target;
	public double weight;

	public Edge (Vertex argTarget, double argWeight) {
		target = argTarget;
		weight = argWeight;
	}

	public String toString() {
		return "" + target + " " + weight;
	}

}


import java.io.IOException;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Mahmoud Aladdin
 */
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);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader jin, PrintWriter jout) {
        int ways = jin.int32();

        int cnt = 0;
        long n = 0;

        PriorityQueue<Pair> que = new PriorityQueue<>(ways, new Comparator<Pair>() {
            @Override
            public int compare(Pair p1, Pair p2) {
                long t1 = p1.x * (long) Math.pow(p1.k, 3);
                long t2 = p2.x * (long) Math.pow(p2.k, 3);
                if(t1 == t2) {
                    return 0;
                } else {
                    return (int)((t1 - t2) / Math.abs(t1 - t2));
                }
            }
        });

        Set<String> seen = new HashSet<>();
        que.add(new Pair(1, 2));
        while(cnt <= ways) {
            Pair cp = que.poll();
            long tn = cp.x * (long) Math.pow(cp.k, 3);
            if(seen.contains(cp.toStr()))
                continue;
            if(cnt == ways) {
                if(tn == n) {
                    jout.println(-1);
                } else {
                    jout.println(n);
                }
                break;
            } else {
                n = tn;

                cnt++;
                que.add(new Pair(cp.x + 1, cp.k));
                que.add(new Pair(cp.x, cp.k + 1));
            }
            seen.add(cp.toStr());
        }
    }
}

class Pair {
    public long x;
    public long k;

    public String toStr() {
        return x + " " + k;
    }

    public Pair(long a, long b) {
        x = a;
        k = b;
    }
}

class InputReader {
    private static final int bufferMaxLength = 1024;
    private InputStream in;
    private byte[] buffer;
    private int currentBufferSize;
    private int currentBufferTop;
    private static final String tokenizers = " \t\r\f\n";

    public InputReader(InputStream stream) {
        this.in = stream;
        buffer = new byte[bufferMaxLength];
        currentBufferSize = 0;
        currentBufferTop = 0;
    }

    private boolean refill() {
        try {
            this.currentBufferSize = this.in.read(this.buffer);
            this.currentBufferTop = 0;
        } catch(Exception e) {}
        return this.currentBufferSize > 0;
    }

    public String line() {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null) {
            tok.append((char)first.byteValue());
            if((char)first.byteValue() == '\n')
                break;
        }
        return tok.toString();
    }

    public Byte readChar() {
        if(currentBufferTop < currentBufferSize) {
            return this.buffer[this.currentBufferTop++];
        } else {
            if(!this.refill()) {
                return null;
            } else {
                return readChar();
            }
        }
    }

    public String token()  {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));
        if(first == null) return null;
        tok.append((char)first.byteValue());
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {
            tok.append((char)first.byteValue());
        }
        return tok.toString();
    }

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

    public Integer int32() throws NumberFormatException {
        String tok = token();
        return tok == null? null : Integer.parseInt(tok);
    }

    public Long int64() throws NumberFormatException {
        String tok = token();
        return tok == null? null : Long.parseLong(tok);
    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Global14 {
	static PrintWriter out;
	static Scanner sc;
	static ArrayList<int[]>q,w,x;
	static ArrayList<Integer>adj[];
	static HashSet<Integer>primesH;
	static boolean prime[];
	//static ArrayList<Integer>a;
	static HashSet<Long>tmp;
	static int[][][]dist;
	static boolean[]v;
	static int[]a,b,c,d;
	static Boolean[][]dp;
	static char[][]mp;
	static int A,B,n,m,h,ans,sum;
	//static String a,b;
	static long oo=(long)1e9+7;
	public static void main(String[]args) throws IOException {
		sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		//A();
		//B();
		//C();
		//D();
		E();
		//F();
		//G();
		out.close();
	}
	  private static void A() throws IOException {
		  int t=ni();
		  while(t-->0) {
				int n=ni(),w=ni();
				a=nai(n);
				int sum=0;
				for(int i=0;i<n;i++)sum+=a[i];
				if(sum==w) {ol("NO");continue;}
				if(sum<w) {
					ol("YES");
					disp2(a);continue;
				}
				Arrays.sort(a);
				int cur=0;
				for(int i=n-1;i>=0;i--) {
					if(cur==w) {
						int tmp=a[i+1];
						a[i+1]=a[i];
						a[i]=tmp;
						break;
					}
					cur+=a[i];
				}
				ol("YES");
				disp2(a);

		  }

	   }
		static void B() throws IOException {
			int t=ni();
			while(t-->0) {
				long n=nl();
				if(n%2==0) {
				n/=2;
				int sq=(int)Math.sqrt(n);
				if(sq*sq==n&&sq!=0) {
					ol("YES");continue;
				}
				}
				if(n%2==0) {
				n/=2;
				 int sq=(int)Math.sqrt(n);
				if(sq*sq==n&&sq!=0) {
					ol("YES");continue;
				}
				}
				ol("NO");
			}
			}

		static void C() throws IOException{
			 int t=ni();
			 while(t-->0) {
				int n=ni(),m=ni(),x=ni();
				int[][]a=new int[n][2];
				int mx=0;
				for(int i=0;i<n;i++) {
					a[i][0]=ni();
					a[i][1]=i;
					mx=Math.max(mx, a[i][0]);
				}
				Arrays.sort(a,(u,v)->u[0]-v[0]);
				PriorityQueue<int[]>vals=new PriorityQueue<int[]>((u,v)->u[0]-v[0]);
				int[]ans=new int[n];
				//int grp=1;
				vals.add(new int[] {a[0][0],1});
				ans[a[0][1]]=1;
				for(int i=1;i<n;i++) {
					if(vals.size()<m) {
						ans[a[i][1]]=vals.size()+1;
						vals.add(new int[] {a[i][0],vals.size()+1});
						mx=Math.max(mx, a[i][0]);
					}else {
						int[]p=vals.poll();
						vals.add(new int[] {p[0]+a[i][0],p[1]});
						ans[a[i][1]]=p[1];
						mx=Math.max(mx, a[i][0]+p[0]);
					}
				}
				if(mx-vals.peek()[0]>x)ol("NO");
				else {

					ol("YES");
					for(int i=0;i<n;i++) {
						out.print(ans[i]+" ");
					}
					ol("");
				}

			 }
		}
		private static Boolean dp(int i, int j) {
			if(j>sum/2)return false;
			if(i==x.size()) {
				return sum/2==j;
			}
			if(dp[i][j]!=null)return dp[i][j];

			return dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);
		}
		static boolean isPrime(long n) {
			if(n==2)return true;
			if(n<2||n%2==0)return false;

			for(long i=3L;i*i<n;i+=2l) {
				long rem=(n%i);
				if(rem==0)return false;
			}
			return true;
		}
		static void D() throws IOException {
			int t=ni();
			while(t-->0) {
				int n=ni(),l=ni(),r=ni();
				int[]occ1=new int[n+1];
				a=nai(n);
				for(int i=0;i<l;i++) {
					occ1[a[i]]++;
				}
				int[]occ2=new int[n+1];
				for(int i=l;i<n;i++) {
					occ2[a[i]]++;
				}
				int base=Math.abs((n/2)-l);
				int tk=0;
				int[]lrg=l>r?occ1:occ2;
				int[]sml=l<=r?occ1:occ2;
				for(int i=0;i<=n&&tk<base;i++) {
					int rem=base-tk;
					int taken=Math.min(rem,
							Math.max(0,(lrg[i]-sml[i])/2));
					lrg[i]-=taken;
					sml[i]+=taken;
					tk+=taken;
				}
				for(int i=0;i<n&&tk<base;i++) {
					if(lrg[i]<=sml[i])continue;
					lrg[i]--;
					sml[i]++;
					tk++;
				}
				int c1=0,c2=0;
				for(int i=0;i<=n;i++) {
					if(lrg[i]>sml[i]) {
						if(c1<0) {
							int diff=Math.min(-c1, -sml[i]+lrg[i]);
							lrg[i]-=diff;
							c1+=diff;
						}
						int nd=lrg[i]-sml[i];
						c2-=nd;
						base+=nd;
						sml[i]=lrg[i];
					}else if(lrg[i]<sml[i]) {
						if(c2<0) {
							int diff=Math.min(-c2, sml[i]-lrg[i]);
							sml[i]-=diff;
							c2+=diff;
						}
						int nd=-lrg[i]+sml[i];
						base+=nd;
						c1-=nd;
						lrg[i]=sml[i];
					}
				}
				ol(base);
			}
		}
		private static int bfs(int i, int j,int k) {
			boolean [][]vis=new boolean[dist.length][dist[0].length];
			Queue<int[]>q=new LinkedList<int[]>();
			int mn=Integer.MAX_VALUE;
			q.add(new int[] {i,j,0,0});
			int[]dx=new int[] {-1,1,0,0};
			int[]dy=new int[] {0,0,1,-1};
			while(!q.isEmpty()) {
				int []x=q.poll();
				vis[x[0]][x[1]]=true;
				int c=x[2];
				if(c>k/2)continue;
				if(c>0&&k%c==0&&(k/c)%2==0) {
					mn=Math.min(mn,x[3]*k/c );
				}
				for(int a=0;a<4;a++) {
					int nx=x[0]+dx[a];
					int ny=x[1]+dy[a];
					if(valid(nx,ny)&&!vis[nx][ny]) {
						q.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});
					}
				}

			}
			return mn;
		}
		private static boolean valid(int nx, int ny) {
			return nx>=0&&nx<dist.length&&ny>=0&&ny<dist[0].length;
		}
		static int gcd (int a, int b) {
		    return b==0?a:gcd (b, a % b);
		}

	static void E() throws IOException {
		int t=1;
		while(t-->0) {
			int n=ni();
			long oo=nl();
			long fc[]=new long[n+1];
			fc[0]=fc[1]=1l;
			long []pow2=new long[n+1];
			pow2[0]=1l;
			for(int i=1;i<pow2.length;i++) {
				pow2[i]=(pow2[i-1]*2l)%oo;
			}
			for(int i=2;i<fc.length;i++) {
				fc[i]=(fc[i-1]*1l*i)%oo;
			}

			long ncr[][]=new long[n+1][n+1];
			for(int i=0;i<=n;i++) {
				for(int j=0;j<=i;j++) {
					ncr[i][j]=i==0||j==0?1l:(ncr[i-1][j-1]+ncr[i-1][j])%oo;
				}
			}
			long ans=0;
			long dp[][]=new long[n+2][n+2];
			dp[0][0]=1;
			for(int i=0;i<n;i++) {
				for(int j=0;j<=i;j++) {
					for(int k=1;i+k<=n;k++) {
						dp[i+k+1][j+k]+=((dp[i][j]*pow2[k-1]%oo)*ncr[j+k][k])%oo;
						//dp[i+k+1][j+k]%=oo;
					}
				}
			}
			for(int i=0;i<=n;i++) {
				ans=(ans+dp[n+1][i])%oo;
			}
			ol(""+ans);
			//ol(""+pow2[3]);
		}

	}

	static void F() throws IOException {
		int t=ni();
		while(t-->0) {

		}
	}
	static void CC() throws IOException {
		for(int kk=2;kk<21;kk++) {
			ol(kk+"   -------");
		int n=kk;
		int k=n-2;
		int msk=1<<k;
		int[]a=new int[k];
		for(int i=0;i<a.length;i++)a[i]=i+2;
		int mx=1;
		int ms=0;
		for(int i=1;i<msk;i++) {
			long prod=1;
			int cnt=0;
			for(int j=0;j<a.length;j++) {
				if(((i>>j)&1)!=0) {
					prod*=a[j];
					cnt++;
				}
			}
			if(cnt>=mx&&prod%n==1) {
				mx=cnt;
				ms=i;
			}

		}
		ol(mx==1?mx:mx+1);
		out.print(1+" ");
		long pr=1;
		for(int j=0;j<a.length;j++) {
			if(((ms>>j)&1)!=0) {
				out.print(a[j]+" ");
				pr*=a[j];
			}
		}
		ol("");
		ol("Prod: "+pr);
		ol(n+"*"+((pr-1)/n)+" + "+1);
		}
	}
	static int ni() throws IOException {
		return sc.nextInt();
	}
	static double nd() throws IOException {
		return sc.nextDouble();
	}
	static long nl() throws IOException {
		return  sc.nextLong();
	}
	static String ns() throws IOException {
		return sc.next();
	}
	static int[] nai(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		return a;
	}
	static long[] nal(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		return a;
	}
	static int[][] nmi(int n,int m) throws IOException{
		int[][]a=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		return a;
	}

	static long[][] nml(int n,int m) throws IOException{
		long[][]a=new long[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextLong();
			}
		}
		return a;
	}
	static void o(String x) {
		out.print(x);
	}
	static void ol(String x) {
		out.println(x);
	}
	static void ol(int x) {
		out.println(x);
	}
	static void disp1(int []a) {
		for(int i=0;i<a.length;i++) {
			out.print(a[i]+" ");
		}
		out.println();
	}
	static void disp2(int []a) {
		for(int i=a.length-1;i>=0;i--) {
			out.print(a[i]+" ");
		}
		out.println();
	}
	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 boolean hasNext() {return st.hasMoreTokens();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}

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

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

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

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

	}
}


import java.util.*;

public class Compute {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int M = sc.nextInt();
        long fact[] = new long[n+1];
        long ifact[] = new long[n+1];
        long dp[][] = new long[n+1][n+1];
        fact[1] = 1;
        ifact[1] = 1;
        dp[1][1] = 1;

        for(int i = 2; i <= n; i++) {
            fact[i] = (i*fact[i-1]) % M;
            ifact[i] = (ifact[M % i]*(M - M/i)) % M;
            dp[i][i] = (dp[i-1][i-1] * 2) % M;
        }

        for(int i = 3; i <= n; i++) {
            for(int j = i/2 + 1; j <= i-1; j++) {
                for(int k = 2; k <= i-1 && ((j - k + 1) > (i - k)/2); k++) {
                    dp[i][j] += ((((dp[k-1][k-1]*dp[i-k][j-k+1] % M)*fact[j] % M)*ifact[k-1] % M)*ifact[j-k+1] % M);
                }
            }
        }

        long sum = 0;
        for(int i = n/2 + 1; i <= n; i++) {

            sum = (sum + dp[n][i]) % M;
        }

        System.out.println(sum % M);
    }
}