mport java.util.Scanner;

public class C {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String burger = sc.nextLine();
		long B = 0;
		long S = 0;
		long C = 0;
		long count = 0;
		for(int i = 0; i < burger.length(); i++){
			if(burger.charAt(i) == 'B'){
				B++;
			}
			if(burger.charAt(i) == 'S'){
				S++;
			}
			if(burger.charAt(i) == 'C'){
				C++;
			}
		}
		long nB = sc.nextLong();
		long nS = sc.nextLong();
		long nC = sc.nextLong();

		long pB = sc.nextLong();
		long pS = sc.nextLong();
		long pC = sc.nextLong();

		long r = sc.nextLong();
		while(true){
			long min = Long.MAX_VALUE;
			if(B != 0){
				min = Math.min(nB/B, min);
			}
			else{
				nB = 0;
			}
			if(S != 0){
				min = Math.min(nS/S, min);
			}
			else{
				nS = 0;
			}
			if(C != 0){
				min = Math.min(nC/C, min);
			}
			else{
				nC = 0;
			}
			count+=min;
			nC -= C*min;
			nS -= S*min;
			nB -= B*min;
			if(nC == nS && nS == nB && nB == 0){
				break;
			}
			if(B!= 0 && nB < B){
				r -= (B-nB)*pB;
				nB = B;
			}
			if(S!= 0 && nS < S){
				r-= (S-nS)*pS;
				nS = S;
			}
			if(C!= 0 && nC < C){
				r-= (C-nC)*pC;
				nC = C;
			}
			if(r < 0){
				break;
			}
		}
		long costOfBurger = B*pB + S*pS + C*pC;
		if(r > 0){
			count += r/costOfBurger;
		}
		System.out.println(count);

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            TaskG solver = new TaskG();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class TaskG {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            IntList inc = new IntList();
            IntList dec = new IntList();
            for (int i = 0; i < n; i++) {
                boolean putInc = inc.isEmpty() ||
                        a[inc.tail()] < a[i];
                boolean putDec = dec.isEmpty() ||
                        a[dec.tail()] > a[i];
                if (putInc && putDec) {
                    if (i + 1 < n && a[i] < a[i + 1]) {
                        inc.add(i);
                    } else {
                        dec.add(i);
                    }
                } else if (putInc) {
                    inc.add(i);
                } else if (putDec) {
                    dec.add(i);
                } else {
                    out.println("NO");
                    return;
                }
            }

            out.println("YES");
            inc.reverse();
            dec.reverse();
            for (int i = 0; i < n; i++) {
                if (dec.isEmpty() || (!inc.isEmpty() && inc.tail() == i)) {
                    inc.pop();
                    out.append(0).append(' ');
                } else {
                    dec.pop();
                    out.append(1).append(' ');
                }
            }
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static void reverse(int[] data, int l, int r) {
            while (l < r) {
                swap(data, l, r);
                l++;
                r--;
            }
        }

        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(String c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class IntList {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntList(IntList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntList() {
            this(0);
        }

        public void reverse(int l, int r) {
            SequenceUtils.reverse(data, l, r);
        }

        public void reverse() {
            reverse(0, size - 1);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public void add(int x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public int tail() {
            checkRange(0);
            return data[size - 1];
        }

        public int pop() {
            return data[--size];
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public boolean isEmpty() {
            return size == 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntList)) {
                return false;
            }
            IntList other = (IntList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + data[i];
            }
            return h;
        }

    }
}


import java.util.*;

public class B
{
   public static void main(String[] args)
   {
      new B(new Scanner(System.in));
   }

   int oo = 987654321;

   int[][] grid;
   int W;
   int H;

   boolean check(int x, int y)
   {
      if (x < 0) return false;
      if (y < 0) return false;
      if (x >= W) return false;
      if (y >= H) return false;
      return true;
   }

   boolean isWall(int x, int y)
   {
      if (!check(x+1, y+1)) return true;
      if (!check(x-1, y+1)) return true;
      if (!check(x+1, y-1)) return true;
      if (!check(x-1, y-1)) return true;
      return false;
   }

   void add(ArrayDeque<Node> q, int x, int y, int d)
   {
      if (!check(x, y)) return;
      if (grid[x][y] <= d) return;
      q.add(new Node(x, y, d));
   }

   void bfs()
   {
      for (int[] gri : grid)
         Arrays.fill(gri, oo);

      ArrayDeque<Node> q = new ArrayDeque<Node>();
      for (int j=0; j<H; j++)
         for (int i=j%2; i<W; i+=2)
            if (isWall(i, j))
               q.add(new Node(i, j, 1));

      while (q.size() > 0)
      {
         Node cur = q.poll();
         if (grid[cur.x][cur.y] <= cur.d) continue;
         grid[cur.x][cur.y] = cur.d;

         add(q, cur.x+1, cur.y+1, cur.d+1);
         add(q, cur.x-1, cur.y+1, cur.d+1);
         add(q, cur.x+1, cur.y-1, cur.d+1);
         add(q, cur.x-1, cur.y-1, cur.d+1);
      }
   }

   public B(Scanner in)
   {
      W = in.nextInt();
      H = in.nextInt();
      grid = new int[W][H];

      int N = in.nextInt();
      bfs();

      int res = 0;
      for (int[] gri : grid)
         for (int v : gri)
            if (v == N)
               res++;
      System.out.printf("%d%n", res);

   }
}

class Node
{
   int x, y, d;

   public Node(int xx, int yy, int dd)
   {
      x=xx; y=yy; d=dd;
   }
}


   public class Main {

   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int x  = in.nextInt();
       int sum = 0;
       int index = 0;
       for(int i = 1; i<=x; i++){
           sum += i;
           if (sum >= x){
               index = i;
               break;
           }
       }

        System.out.println(index);
    }
   }


import java.util.*;
import java.io.*;
public class Edu104F{
	public static void main(String[] main) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		PrintWriter out = new PrintWriter(System.out);
		String s = st.nextToken();
		int[] num = new int[s.length()+1];
		num[1] = s.charAt(0) - 48;
		for(int i = 2; i <= s.length(); i++) {
			num[i] = s.charAt(i-1) - s.charAt(i-2);
		}
		int iters = 0;
		boolean edit = true;
		int min = 10000;
		while(edit) {
			iters++;
			edit = false;
			for(int i = 1; i < s.length(); i++) {
				if(num[i] > 5) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(num[i] == 5 && num[i-1] < 0) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && (num[s.length()] > 0 || num[s.length()] <= -4)) {
					num[i-2]++;
					num[i-1] = -5;
					num[i] = -5;
					num[s.length()]-=2;
					edit = true;
				}
				else if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && num[s.length()] < -3 && num[s.length() - 1] > 0) {
					num[i-2]++;
					num[i-1] = -5;
					num[i] = -5;
					num[s.length()]-=2;
					edit = true;
				}
				else if(num[i] == 5 && num[i-1] == 5 && num[s.length()] > 1) {
					num[i-2]++;
					num[i-1] = -4;
					num[i] = -5;
					num[s.length()]-=2;
					edit = true;
				}
				else if(num[i] == 5 && num[i-1] == 5 && num[i-2] == 5) {
					num[i-2]++;
					num[i-1] = -4;
					num[i] = -5;
					num[s.length()]-=2;
					edit = true;
				}
				else if(num[i] < -5) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
				else if(num[i] == -5 && num[i-1] > 0) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
				else if(i >= 2 && num[i] == -5 && num[i-1] == -4 && (num[i-2] > 0 || num[i-2] == -4) && (num[s.length()] < 0 || num[s.length()] >= 4)) {
					num[i-2]--;
					num[i-1] = 5;
					num[i] = 5;
					num[s.length()]+=2;
					edit = true;
				}
				else if(i >= 2 && num[i] == -5 && num[i-1] == -4 && num[i-2] > 0 && num[s.length()] > 3 && num[s.length() - 1] < 0) {
					num[i-2]--;
					num[i-1] = 5;
					num[i] = 5;
					num[s.length()]+=2;
					edit = true;
				}
				else if(num[i] == -5 && num[i-1] == -5 && num[s.length()] < -1) {
					num[i-2]--;
					num[i-1] = 4;
					num[i] = 5;
					num[s.length()]+=2;
					edit = true;
				}
				else if(num[i] == -5 && num[i-1] == -5 && num[i-2] == -5) {
					num[i-2]--;
					num[i-1] = 4;
					num[i] = 5;
					num[s.length()]+=2;
					edit = true;
				}
			}
			if(num[s.length()] > 6) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(num[s.length()] >= 5 && num[s.length() - 1] < 0) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(s.length() >= 2 && num[s.length()] == 6 && num[s.length()-1] == 4 && num[s.length()-2] < 0) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(num[s.length()] < -6) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
			else if(num[s.length()] <= -5 && num[s.length() - 1] > 0) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
			else if(s.length() >= 2 && num[s.length()] == -6 && num[s.length()-1] == -4 && num[s.length()-2] > 0) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
			int ans = 0;
			for(int i = 0; i <= s.length(); i++) {
				//out.print(num[i] + " ");
				ans += (s.length() + 1 - i)*Math.abs(num[i]);
			}
			min = Math.min(ans, min);
			if(iters > 7000000)
				break;
		}
		int ans = 0;
		for(int i = 0; i <= s.length(); i++) {
			//out.print(num[i] + " ");
			ans += (s.length() + 1 - i)*Math.abs(num[i]);
		}
		out.println(Math.min(min,ans));
		out.close();
	}
}


import java.util.*;
import java.io.*;
public class Edu104F{
	public static void main(String[] main) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		PrintWriter out = new PrintWriter(System.out);
		String s = st.nextToken();
		int[] num = new int[s.length()+1];
		num[1] = s.charAt(0) - 48;
		for(int i = 2; i <= s.length(); i++) {
			num[i] = s.charAt(i-1) - s.charAt(i-2);
		}
		boolean edit = true;
		while(edit) {
			edit = false;
			for(int i = 1; i < s.length(); i++) {
				if(num[i] > 5) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(num[i] == 5 && num[i-1] < 0) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && num[s.length()] > 0) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(num[i] == 5 && num[i-1] == 5 && num[s.length()] > 0) {
					num[i-1]++;
					num[i] = num[i]-10;
					num[s.length()]--;
					edit = true;
				}
				else if(num[i] < -5) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
				else if(num[i] == -5 && num[i-1] > 0) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
				else if(i >= 2 && num[i] == -5 && num[i-1] == -4 && num[i-2] > 0 && num[s.length()] < 0) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
				else if(num[i] == -5 && num[i-1] == -5 && num[s.length()] < 0) {
					num[i-1]--;
					num[i] = num[i]+10;
					num[s.length()]++;
					edit = true;
				}
			}
			if(num[s.length()] > 6) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(num[s.length()] >= 5 && num[s.length() - 1] < 0) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(s.length() >= 2 && num[s.length()] == 6 && num[s.length()-1] == 4 && num[s.length()-2] < 0) {
				num[s.length()-1]++;
				num[s.length()] -= 11;
				edit = true;
			}
			else if(num[s.length()] < -6) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
			else if(num[s.length()] <= -5 && num[s.length() - 1] > 0) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
			else if(s.length() >= 2 && num[s.length()] == -6 && num[s.length()-1] == -4 && num[s.length()-2] > 0) {
				num[s.length()-1]--;
				num[s.length()] += 11;
				edit = true;
			}
		}
		int ans = 0;
		for(int i = 0; i <= s.length(); i++) {
			//out.print(num[i] + " ");
			ans += (s.length() + 1 - i)*Math.abs(num[i]);
		}
		out.println(ans);
		out.close();
	}
}


import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

// Please name your class Main
public class Main {
    static FastScanner fs=new FastScanner();
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        int Int() {
            return Integer.parseInt(next());
        }

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

        String Str(){
            return next();
        }
    }

    public static void main (String[] args) throws java.lang.Exception {
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        //reading /writing file
        //Scanner in=new Scanner(System.in);
        //Scanner in=new Scanner(new File("input.txt"));
        //PrintWriter pr=new PrintWriter("output.txt");

        int T=1;
        for(int t=0;t<T;t++){
            Solution sol1=new Solution(out,fs);
            sol1.solution(T,t);
        }
        out.flush();

    }

    public static int[] Arr(int n){
        int A[]=new int[n];
        for(int i=0;i<n;i++)A[i]=Int();
        return A;
    }
    public static int Int(){
        return fs.Int();
    }
    public static long Long(){
        return fs.Long();
    }
    public static String Str(){
        return fs.Str();
    }

}

class Solution {
    PrintWriter out;
    int INF = Integer.MAX_VALUE;
    int NINF = Integer.MIN_VALUE;
    int MOD = 998244353;
    int mod = 1000000007;
    Main.FastScanner fs;

    public Solution(PrintWriter out, Main.FastScanner fs) {
        this.out = out;
        this.fs = fs;

    }

    public void solution(int all, int testcase) {
        int n = fs.Int();
        mod = fs.Int();

        int dp[][] = new int[n][n * n + 5];
        dp[0][0] = 1;
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < dp[0].length; j++) {
                for(int cnt = 0; cnt <= i; cnt++){
                    if(j - cnt >= 0) {
                        dp[i][j] += dp[i - 1][j - cnt];
                        dp[i][j] %= mod;
                    }
                }
            }
        }

        int sums[][] = new int[dp.length][dp[0].length];
        for(int i = 0; i < dp.length;i++){
            int sum = 0;
            for(int j = 0; j < dp[0].length; j++){
                sum += dp[i][j];
                sum %= mod;
                sums[i][j] = sum;
            }
        }

        long fact[] = new long[3000];
        fact[0] = fact[1] = 1;
        for(int i = 2; i < fact.length;i++){
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }

        long ncr[][] = new long[55][55];
        ncr[0][0]=1;
        for (int i=1;i<ncr.length;i++) {
            ncr[i][0]=1;
            for (int j=1;j<ncr[0].length;j++) {
                ncr[i][j]=(ncr[i-1][j] + ncr[i-1][j-1])%mod;
            }
        }

        long res = 0;
        for(int i = n - 2; i >= 0; i--) {
            int cnt = n - i;
            int pre = n - cnt;
            long com = (ncr[n][pre] * fact[pre]) % mod;
            long sum = 0;

            for(int dif = 1; dif < cnt; dif++){
                for(int inv = dif; inv < dp[0].length; inv++){
                    if(dp[cnt - 1][inv] == 0){
                        break;
                    }
                    if(inv - dif - 1 < 0)continue;
                    long x = dp[cnt - 2][inv];
                    long y = sums[cnt - 2][inv - dif - 1];
                    x *= y;
                    x %= mod;
                    sum += x * (cnt - dif);
                    sum %= mod;
                }
            }
            res += sum * com;
            res%=mod;
        }

        out.println(res);
    }

}


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

import static java.lang.Integer.min;

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

        solve(s.nextInt(), s.nextInt());
    }

    public static void solve(int n, int mod) {
        ArrayList<int[]> inversions = new ArrayList<>();
        inversions.add(new int[]{1});

        int last[];
        int next[];
        for (int i = 1; i < n; i++) {
            last = inversions.get(i - 1);
            next = new int[i * (i + 1) / 2 + 1];

            int e;
            for (int j = 0; j < next.length; j++) {
                e = 0;
                for (int k = min(j, i); k >= 0; k--) {
                    if (j - k < last.length) {
                        e += last[j - k];
                        e = e % mod;
                    }
                }
                next[j] = e;
            }

            inversions.add(next);
        }

        for (int i = 0; i < n; i++) {
            //System.out.println(Arrays.toString(inversions.get(i)));
        }

        int perms[] = new int[n];
        perms[0] = 0;

        int c;
        int inv[];
        for (int i = 1; i < n; i++) {
            c = (perms[i - 1] * i) % mod;

            inv = inversions.get(i - 1);
            for (int j = 0; j < inv.length; j++) {
                for (int k = j + 2; k < inv.length; k++) {
                    c = (c + inv[j] * inv[k] * (k - j - 1) * (2 * i - (k - j - 2)) / 2) % mod;
                }
            }

            perms[i] = c;
        }

        System.out.println(perms[n - 1]);
    }

    public static int fact(int n, int mod) {
        int erg = 1;
        for (int i = 1; i <= n; i++) {
            erg = (erg * i) % mod;
        }
        return erg;
    }
}


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

public class D {
    private static final int MOD = 998244353;

    private static long solve(int n) {
        long[][] s = new long[n + 1][n + 1];
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= i; ++j) {
                if ((2 * i) % (2 * j) == 0) {
                    s[i][j] = 1;
                }
            }
        }

        long[] dp = new long[n + 1];
        dp[1] = 1;
        long[] c = new long[n + 1];
        for (int i = 2; i <= n; ++i) {
            for (int j = 1; j < i; ++j) {
                c[i] = (c[i] + dp[j]) % MOD;
            }
            for (int j = 1; j <= i; ++j) {
                dp[i] = (dp[i] + s[i][j]) % MOD;
            }
            dp[i] = (dp[i] + c[i]) % MOD;
        }

        return dp[n];
    }

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

        int n = Integer.parseInt(in.readLine());
        System.out.println(solve(n));

        in.close();
    }
}


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

public class cforces{
    static Templates.FastScanner sc = new Templates.FastScanner();
    static PrintWriter fop = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {

        D();

    }

    static void D() throws IOException{
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n = Integer.parseInt(bu.readLine());
        int i,j;
        long f[] = new long[n+1], dp[] = new long[n+1];
        for(i=2;i<=n;i++)
        if(f[i]==0)
        for(j=i;j<=n;j+=i){
            if(f[j]==0) f[j]=1;
            int x=j,c=1;
            while(x%i==0){
                c++;
                x/=i;
            }
            f[j]*=c;

        }
        dp[1]=1;
        long sum=1,M = 998244353;
        for(i=2;i<=n;i++){
            dp[i] = (sum+f[i])%M;
            sum = (sum+dp[i])%M;
        }
        System.out.println(dp[n]);
    }

}


					/*
					ID: abdelra29
LANG: JAVA
PROG: zerosum
					*/
						/*
						TO LEARN

						2-euler tour

						*/
						/*
						TO SOLVE
						*/
						/*
						bit manipulation shit
						1-Computer Systems: A Programmer's Perspective
						2-hacker's delight
						*/
						/*
						TO WATCH

						*/
						            import java.util.*;
								    import java.math.*;
								    import java.io.*;
								    import java.util.stream.Collectors;

								       public class A{
						            static FastScanner scan=new FastScanner();
									     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
static long n,mod;
static long add(long a,long b)
{
	a+=b;
	if(a>=mod)
		return a-=mod;
	return a;
}
static long sub(long a,long b)
{
	a-=b;
	if(a<0)
		a+=mod;
	if(a>=mod)
		return a-=mod;
	return a;
}
		public static void main(String[] args)  throws Exception
						      {
						 /*
						 very important tips
						 1-just fucking think backwards once in your shitty life
						 2-consider brute forcing and finding some patterns and observations
						 3-when you're in contest don't get out because you think there is no enough time
						 4-don't get stuck on one approach
						 */
					    //	File file=new File("D:\\input\\out.txt");
					//scan=new FastScanner("moop.in");
					//	out = new PrintWriter("moop.out");

								 							 /*
								 READING

								 3-Introduction to DP with Bitmasking codefoces
								 4-Bit Manipulation hackerearth
								 5-read more about mobious and inculsion-exclusion
								 6-read more about fermat little theorem
								 */
								//int l=scan.nextInt();
								//int x=scan.nextInt();
								/*for(int x=1;x<=l;x++){
									for(int j=1;j<=l;j++){
								for(int i=2;i<=l;i++)
								{
									int cnt=0;
										if(j/i==x){
											//cnt++;
											System.out.println(x+" "+i+" "+j);
										}
								}

							//	System.out.println();
							}
						}*/

								int tt =1;
							//	tt=scan.nextInt();
								int T=1;
							 outer:while(tt-->0)
								    {
								    	n=scan.nextLong();
								    	mod=scan.nextLong();
								    	long dp[]=new long[(int)(n+n+1)];
								    	dp[(int)n]=1;
								    	long suf[]=new long[(int)(n+n+1)];
								    	suf[(int)n]=1;
								    	for(int i=(int)n-1;i>=1;i--)
								    	{
								    		int j=2;
								    		suf[i]=suf[i+1];
								    		dp[i]=add(dp[i],suf[i+1]);
								    		while(true)
								    		{
								    			if(i*j>n)
								    				break;
								    			//out.println(i+" "+(i*j)+" "+((j*(i+1)-1)));
								    			dp[i]=add(dp[i],sub(suf[i*j],suf[j*(i+1)]));
								    			j++;
								    		}
								    		suf[i]=add(suf[i],dp[i]);
								    	}
								    	out.println(dp[1]);

}

		out.close();
					}

					static class special implements Comparable<special>{
					int cnt,idx;
					String s;
					public special(int cnt,int idx,String s)
					{
						this.cnt=cnt;
						this.idx=idx;
						this.s=s;
					}

						 @Override
								            public int hashCode() {
								                return (int)42;
								            }
						  @Override
								            public boolean equals(Object o){
								            //	System.out.println("FUCK");
								                if (o == this) return true;
								                if (o.getClass() != getClass()) return false;
								                special t = (special)o;
								                return t.cnt == cnt && t.idx == idx;
								            }
								            public int compareTo(special o1)
								            {
								            	if(o1.cnt==cnt)
								            	{
								            		return o1.idx-idx;
								            	}
								            	return o1.cnt-cnt;
								            }
					}

								     static long binexp(long a,long n)
								    {
								        if(n==0)
								            return 1;
								        long res=binexp(a,n/2);
								        if(n%2==1)
								            return res*res*a;
								        else
								            return res*res;
								    }

								    static long powMod(long base, long exp, long mod) {
								           if (base == 0 || base == 1) return base;
								           if (exp == 0) return 1;
								           if (exp == 1) return (base % mod+mod)%mod;
								           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
								           R *= R;
								           R %= mod;
								           if ((exp & 1) == 1) {
								               return (base * R % mod+mod)%mod;
								           }
								           else return (R %mod+mod)%mod;
								       }
								    static double dis(double x1,double y1,double x2,double y2)
								    {
								        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
								    }
								    static long mod(long x,long y)
								        {
								            if(x<0)
								                x=x+(-x/y+1)*y;
								            return x%y;
								        }
								     public static  long pow(long b, long e) {
								                long r = 1;
								                while (e > 0) {
								                    if (e % 2 == 1) r = r * b ;
								                    b = b * b;
								                    e >>= 1;
								                }
								                return r;
								            }
								    private static void sort(int[] arr) {
								            List<Integer> list = new ArrayList<>();
								            for (int object : arr) list.add(object);
								            Collections.sort(list);
								        //Collections.reverse(list);
								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
								        }
								    private static void sort2(long[] arr) {
								            List<Long> list = new ArrayList<>();
								            for (Long object : arr) list.add(object);
								            Collections.sort(list);
								        Collections.reverse(list);
								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
								        }
								     static class FastScanner
						{
						    private int BS = 1 << 16;
						    private char NC = (char) 0;
						    private byte[] buf = new byte[BS];
						    private int bId = 0, size = 0;
						    private char c = NC;
						    private double cnt = 1;
						    private BufferedInputStream in;

						    public FastScanner() {
						        in = new BufferedInputStream(System.in, BS);
						    }

						    public FastScanner(String s) {
						        try {
						            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
						        } catch (Exception e) {
						            in = new BufferedInputStream(System.in, BS);
						        }
						    }

						    private char getChar() {
						        while (bId == size) {
						            try {
						                size = in.read(buf);
						            } catch (Exception e) {
						                return NC;
						            }
						            if (size == -1) return NC;
						            bId = 0;
						        }
						        return (char) buf[bId++];
						    }

						    public int nextInt() {
						        return (int) nextLong();
						    }

						    public int[] nextInts(int N) {
						        int[] res = new int[N];
						        for (int i = 0; i < N; i++) {
						            res[i] = (int) nextLong();
						        }
						        return res;
						    }

						    public long[] nextLongs(int N) {
						        long[] res = new long[N];
						        for (int i = 0; i < N; i++) {
						            res[i] = nextLong();
						        }
						        return res;
						    }

						    public long nextLong() {
						        cnt = 1;
						        boolean neg = false;
						        if (c == NC) c = getChar();
						        for (; (c < '0' || c > '9'); c = getChar()) {
						            if (c == '-') neg = true;
						        }
						        long res = 0;
						        for (; c >= '0' && c <= '9'; c = getChar()) {
						            res = (res << 3) + (res << 1) + c - '0';
						            cnt *= 10;
						        }
						        return neg ? -res : res;
						    }

						    public double nextDouble() {
						        double cur = nextLong();
						        return c != '.' ? cur : cur + nextLong() / cnt;
						    }

						    public double[] nextDoubles(int N) {
						        double[] res = new double[N];
						        for (int i = 0; i < N; i++) {
						            res[i] = nextDouble();
						        }
						        return res;
						    }

						    public String next() {
						        StringBuilder res = new StringBuilder();
						        while (c <= 32) c = getChar();
						        while (c > 32) {
						            res.append(c);
						            c = getChar();
						        }
						        return res.toString();
						    }

						    public String nextLine() {
						        StringBuilder res = new StringBuilder();
						        while (c <= 32) c = getChar();
						        while (c != '\n') {
						            res.append(c);
						            c = getChar();
						        }
						        return res.toString();
						    }

						    public boolean hasNext() {
						        if (c > 32) return true;
						        while (true) {
						            c = getChar();
						            if (c == NC) return false;
						            else if (c > 32) return true;
						        }
						    }
						}

								     static class Pair implements Comparable<Pair>{
								            public long x, y,z;
								            public Pair(long x1, long y1,long z1) {
								                x=x1;
								                y=y1;
								                z=z1;
								            }
								             public Pair(long x1, long y1) {
								                x=x1;
								                y=y1;

								            }

								            @Override
								            public int hashCode() {
								                return (int)(x + 31 * y);
								            }
								            public String toString() {
								                return x + " " + y+" "+z;
								            }
								            @Override
								            public boolean equals(Object o){
								                if (o == this) return true;
								                if (o.getClass() != getClass()) return false;
								                Pair t = (Pair)o;
								                return t.x == x && t.y == y&&t.z==z;
								            }
								    public int compareTo(Pair o)
								    {

								  if(x==o.x)
								  	return (int)(y-o.y);
								    	return (int)(x-o.x);

								        }

								    }
								}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.io.*;

public class UpTheStrip {

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

	 }

	public static long solution(long n, long m) {

		long[] dp  = new long[(int)n];
		long[] sum  = new long[(int)n];
		dp[0] = 1;
		sum[0] = 0;
		long prev = 1;

		for(int i = 2; i<=n; i++) {

			dp[i-1] = prev;

			sum[i-1] = (sum[i-1] + sum[i-2])%m;
			sum[i-1] = (sum[i-1] + dp[0])%m;
			dp[i-1] = (dp[i-1] + sum[i-1])%m;

			prev = (prev + dp[i-1])%m;

            int j = i+i;

			while(j<=n)
			{
				sum[j-1] = (sum[j-1] + dp[i-1])%m;
				sum[j-1] = (sum[j-1] - dp[i-2] + m)%m;
				j+=i;
			}
		}

		return dp[(int)n-1];

	}

private static PrintWriter out = new PrintWriter(System.out);

public static void main (String[] args)
{
	MyScanner s =  new MyScanner();

    long n = s.nextLong();
    long m = s.nextLong();
    out.println(solutionn(n,m));

    out.flush();
    out.close();

}
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner in= new Scanner(System.in);
      long a= in.nextLong(), b= in.nextLong();
      String s1= binary(a), s2= binary(b);
      String reverse= (new StringBuilder(s1).reverse()).toString();
      if(check(s1,s2) || check(reverse,s2)) System.out.println("YES");
      else System.out.println("NO");

    }
    private static String binary(long a){
        String res="";
        while(a>0){
            res= (a%2)+res;
            a/=2;
        }
        return res;
    }
    private static boolean check(String s1, String s2){
        int l=0, r= s1.length()-1;
        while(l<s1.length()){
            if(s1.charAt(l)=='1') break;
            l++;
        }
        while(r>=l){
            if(s1.charAt(r)=='1') break;
            r--;
        }
        s1= s1.substring(l,r+1);
        l= s2.indexOf(s1);
        if(l==-1) return false;
        r= l+s1.length();
        if(r<s2.length()){
            if(s2.charAt(s2.length()-1)=='0') return false;
        }
        return true;

    }

}


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

public class F {

	public static long reverse(long n) {
		long rev = 0;
		while (n > 0){
			rev <<= 1;
			if ((long)(n & 1) == 1) rev ^= 1;
			n >>= 1;
		}
		return rev;
	}

	public static long addAndReverse(long n) {
		StringBuilder bin = new StringBuilder(Long.toBinaryString(n));
		bin.append("1");
		bin = bin.reverse();
		return Long.parseLong(bin.toString(), 2);

	}

	static boolean isPowerOfTwo (long x) {
		return x!=0 && ((x&(x-1)) == 0);
	}

	public static long pow2(long n) {
		long p = 1;
		if (n > 0 && (n & (n - 1)) == 0) return n;
		while (p < n) p <<= 1;
		return p;
	}

	static HashSet<Long> set = new HashSet<>();
	public static boolean solve(long x, long y) {
//		System.out.println("x: " + x + " y: " + y);
		if(x==y) return true;
		if(reverse(x)==y) return true;
//		if(reverse(x)>y) return false;
		set.add(x);
		if(x<y) { //go right
			if(!set.contains(reverse(x)))
				return solve(addAndReverse(x), y) || solve(reverse(x), y);
			else return solve(addAndReverse(x), y);
		}
		else { //go left
			return solve(reverse(x), y);
		}
	}

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

		FastScanner scan = new FastScanner();
		PrintWriter output = new PrintWriter(System.out);
		long x = scan.nextLong(), y = scan.nextLong();
		output.println(solve(x, y) ? "YES" : "NO");
		output.flush();
	}

	public static int[] sort(int arr[]) {
		List<Integer> list = new ArrayList<>();
		for(int i:arr) list.add(i);
		Collections.sort(list);
		for(int i = 0;i<list.size();i++) arr[i] = list.get(i);
		return arr;
	}

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

	public static void printArray(int arr[]) {
		for(int i:arr) System.out.print(i+" ");
		System.out.println();
	}

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

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

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

}


import java.util.*;
import java.io.*;
public class Main {
	 	static long mod = 1000000007;
		static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		static boolean poss;
		static HashMap<String,Integer> hm ;
		public static void main(String[] args) throws IOException  {
			FastReader sc = new FastReader();
			int t = 1;
			while( t-- > 0) {
				poss = false;
				int n = sc.nextInt();
				hm = new HashMap<>();
				long x = sc.nextLong();
				long moves = dfs( n , x , 0 );
				if( poss) {
					out.println(moves);
				}
				else {
					out.println(-1);
				}
			}
			out.flush();
		}

		/*
		 * time for a change
		 */
		public static boolean ifpowof2(long n ) {
			return ((n&(n-1)) == 0);
		}
		static long dfs( int n , long x , int move){
	    String s = "";
	    s+=x;
            if( hm.containsKey(s)){
                return hm.get(s);
            }

	    int len = s.length();
	    if( len == n){
	    	poss = true;
	    	hm.put(s , 0);
	        return 0;
	    }

	    HashSet<Integer> hs= new HashSet<>();
	    for( int i =0 ; i< len ;i++){
	        if( s.charAt(i) >'1'){
	            hs.add( s.charAt(i) - '0');
	        }
	    }
            long moves = Integer.MAX_VALUE;
	    for( long y: hs){a
	       moves = Math.min( 1 + dfs( n, x*y , move+1) , moves);
	    }
            if( moves == Integer.MAX_VALUE){
                return moves;
            }
            hm.put(s , (int)moves);
            return moves;
	}
		static boolean isprime(long x ) {
			if( x== 2) {
				return true;
			}
			if( x%2 == 0) {
				return false;
			}
			for( long i = 3 ;i*i <= x ;i+=2) {
				if( x%i == 0) {
					return false;
				}
			}
			return true;
		}

		static boolean[] sieveOfEratosthenes(long n) {
			boolean prime[] = new boolean[(int)n + 1];
			for (int i = 0; i <= n; i++) {
				prime[i] = true;
			}
			for (long p = 2; p * p <= n; p++) {
				if (prime[(int)p] == true) {
					for (long i = p * p; i <= n; i += p)
						prime[(int)i] = false;
				}
			}
			return prime;
		}

		public static int[] nextLargerElement(int[] arr, int n)	{
			Stack<Integer> stack = new Stack<>();
			int rtrn[] = new int[n];
			rtrn[n-1] = -1;
	        stack.push( n-1);
	        for( int i = n-2 ;i >= 0 ; i--){
	            int temp = arr[i];
	            int lol = -1;
	            while( !stack.isEmpty() && arr[stack.peek()] <= temp){
	            	if(arr[stack.peek()] == temp ) {
	            		lol = stack.peek();
	            	}
	                stack.pop();
	            }
	            if( stack.isEmpty()){
	            	if( lol != -1) {
	            		rtrn[i] = lol;
	            	}
	            	else {
	            		rtrn[i] = -1;
	            	}
	            }
	            else{
	            	rtrn[i] = stack.peek();
	            }
	            stack.push( i);
	        }
	        return rtrn;
		}

		static void mysort(int[] arr) {
			for(int i=0;i<arr.length;i++) {
	            int rand = (int) (Math.random() * arr.length);
	            int loc = arr[rand];
	            arr[rand] = arr[i];
	            arr[i] = loc;
	        }
	        Arrays.sort(arr);
	    }

		static void mySort(long[] arr) {
	        for(int i=0;i<arr.length;i++) {
	            int rand = (int) (Math.random() * arr.length);
	            long loc = arr[rand];
	            arr[rand] = arr[i];
	            arr[i] = loc;
	        }
	        Arrays.sort(arr);
	    }

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

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

		 static long rightmostsetbit(long n) {
			 return n&-n;
		 }

		 static long leftmostsetbit(long n)
		    {
		        long k = (long)(Math.log(n) / Math.log(2));
		        return k;
		    }

		 static HashMap<Long,Long> primefactor( long n){
			 HashMap<Long ,Long> hm = new HashMap<>();
			 long temp = 0;
			 while( n%2 == 0) {
				 temp++;
				 n/=2;
			 }
			 if( temp!= 0) {
				 hm.put( 2L, temp);
			 }
			 long c = (long)Math.sqrt(n);
			 for( long i = 3 ; i <= c ; i+=2) {
				 temp = 0;
				 while( n% i == 0) {
					 temp++;
					 n/=i;
				 }
				 if( temp!= 0) {
					 hm.put( i, temp);
				 }
	 		 }
	 		 if( n!= 1) {
	 			 hm.put( n , 1L);
	 		 }
	 		 return hm;
		 }

		 static ArrayList<Long> allfactors(long abs) {
			 HashMap<Long,Integer> hm = new HashMap<>();
			 ArrayList<Long> rtrn = new ArrayList<>();
			 for( long i = 2 ;i*i <= abs; i++) {
				 if( abs% i == 0) {
					 hm.put( i , 0);
					 hm.put(abs/i, 0);
				 }
			 }
			 for( long x : hm.keySet()) {
				 rtrn.add(x);
			 }

			 if( abs != 0) {
				 rtrn.add(abs);
			 }

			 return rtrn;
		 }

		 public static int[][] prefixsum( int n , int m , int arr[][] ){
			 int prefixsum[][] = new int[n+1][m+1];
			 for( int i = 1 ;i <= n ;i++) {
				 for( int j = 1 ; j<= m ; j++) {
					 int toadd = 0;
					 if( arr[i-1][j-1] == 1) {
						 toadd = 1;
					 }
					 prefixsum[i][j] = toadd + prefixsum[i][j-1] + prefixsum[i-1][j] - prefixsum[i-1][j-1];
				 }
			 }
			 return prefixsum;
		 }

		 static class FastReader {
			 BufferedReader br;
			 StringTokenizer st;

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

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

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

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

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

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


import java.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";
    private final String space = " ";

    boolean isConsonantUpperCase(char c) {
        return !isVowelUpperCase(c);
    }

    // only for upper case
    boolean isVowelUpperCase(char c) {
        c = (c + "").toUpperCase().charAt(0);
        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());
    }

    String nextToken() throws IOException {
        if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(line());

        return st.nextToken();

    }

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

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

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

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

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

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

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

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

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

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

    double[] rda(int n) throws IOException {
        double[] arr = new double[n];
        for (int i = 0; i < n; i++) {
            arr[i] = rd();
        }
        return arr;
    }

    void ol(Object... arg) throws IOException {
        int n = arg.length;
        for (int i = 0; i < n - 1; i += 1) {
            os(arg[i].toString());
        }
        if (n > 0) ol(arg[n - 1].toString());
    }

    void ol() throws IOException {
        out.write(endl);
    }

    void os() throws IOException {
        out.write(space);
    }

    void ol(String s) throws IOException {
        out.write(s + endl);
    }

    void os(String s) throws IOException {
        out.write(s + space);
    }

    void ol(int n) throws IOException {
        out.write(n + endl);
    }

    void os(int s) throws IOException {
        out.write(s + space);
    }

    void ol(long s) throws IOException {
        out.write(s + endl);
    }

    void os(long s) throws IOException {
        out.write(s + space);
    }

    void o(String s) throws IOException {
        out.write(s);
    }

    void o(int n) throws IOException {
        out.write(n + "");
    }

    void o(long s) throws IOException {
        out.write(s + "");
    }

    // 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() {

    }
    // make debugging flag based
    private void solveTestCase(int testCaseNumber) throws Exception {

        int steps = 0;

        int n = ri();
        long x = rl();

        Set<Long> set = new TreeSet<>();
        set.add(x);
        while(steps <= 64) {
//            ol(set);
            Set<Long> newSet = new TreeSet<>();

            for (Long m : set) {
                if ((m + "").length() >= n) {
                    ol(steps);return;
                }
                long temp = m;
                while(m > 0) {
                    long digit = m % 10;
                    m/=10;

                    newSet.add(temp * digit);
                }
            }

            set = newSet;
            steps += 1;
        }

        ol(-1);

    }

}


import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Code
{
    int P1,P2,H,S;
    long T1,T2;
    void run() {
        int tc=1;
        StringBuilder sb=new StringBuilder();
        while(tc-->0) {
            P1=ni(); T1=nl();
            P2=ni(); T2=nl();
            H=ni(); S=ni();
            long g = gcd(T1, T2);
            if (g > 1) {
              T1 /= g;
              T2 /= g;
            }
            if(T1>T2) {
                P1^=P2^(P2=P1);
                T1^=T2^(T2=T1);
            }
            if (T1 == T2) {
                int d = P1+P2-S;
                int round = (H + d - 1) / d;
                sb.append(round * T1 * g).append("\n");
                break;
            }
            dp = new Long[H+1];
            // dp = new HashMap<>();
            solve(P1, T1, P2, T2, H, S, 0);
            sb.append(ans*g).append("\n");
        }
        out.println(sb);
        out.flush();
        out.close();
    }
    Long dp[], ans=Long.MAX_VALUE;
    // Map<String, Long> dp;
    void solve(int p1, long t1, int p2, long t2, int h, int s, long time) {
        if(h<=0) {
            ans=min(ans, time);
            return;
        }

        if(dp[h]!=null && dp[h]<time) return;

        // int diff=Math.abs(c1-c2);
        // String str = concat(h);
        // if(dp.containsKey(str) && dp.get(str)) return dp.get(str);
        // 5000*5000=2.5*10^7

        // long res = 0;
        if(t1+T1<=t2) {
            dp[h]=time+t1;
            solve(p1, T1, p2, t2-t1, h-(p1-s), s, time+t1);
        }
        else if(t1>t2) {
            dp[h]=time+t2;
            solve(p1, T1, p2, T2, h-(p1+p2-s), s, time+t1);
            solve(p1, t1-t2, p2, T2, h-(p2-s), s, time+t2);
            // res = min(x,y);
        }
        else {
            dp[h]=time+t1;
            solve(p1, T1, p2, t2-t1, h-(p1-s), s, time+t1);
            solve(p1, T1, p2, T2, h-(p1+p2-s), s, time+t2);
            // System.out.println(h+" "+x+" "+y);
            // res = min(x,y);
        }
        // dp.put(str, res);
        // return res;

    }
    String concat(Long... v) {
        StringBuilder sb = new StringBuilder();
        for(Long i: v) sb.append(i).append(" ");
        return sb.toString();
    }
    StringBuilder pr(String s, int t) {
        return new StringBuilder().append("Case #").append(t).append(": ").append(s).append("\n");
    }
    public static void main(String[] args)throws Exception {
        try {
            // new Thread(null, new Code()::run, "1", 1 << 26).start();
            new Thread(null, new Code("ONLINE_JUDGE")::run, "1", 1 << 26).start();
        } catch(Exception e) {}
    }

    FastReader sc=null;PrintWriter out = null;
    public Code()throws Exception {
        sc = new FastReader(new FileInputStream("input.txt"));
        out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
    }
    public Code(String JUDGE) {
        sc = new FastReader(System.in);
        out = new PrintWriter(System.out);
    }

    String ns() { return sc.next(); }
    int ni() { return sc.nextInt(); }
    long nl() { return sc.nextLong(); }
    int[] ni(int n) {
        int a[]=new int[n];
        for(int i=0;i<n;a[i++]=ni());
        return a;
    }
    long[] nl(int n) {
        long a[]=new long[n];
        for(int i=0;i<n;a[i++]=nl());
        return a;
    }

    int[][] ni(int n,int m) {
        int a[][]=new int[n][m];
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                a[i][j]=ni();
        return a;
    }
    long[][] nl(int n,int m) {
        long a[][]=new long[n][m];
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                a[i][j]=nl();
        return a;
    }
    long gcd(long a, long b) {
        return b==0?a:gcd(b,a%b);
    }
    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;
        public FastReader(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 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 = res*1L*10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res *1L* sgn;
        }

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

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

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

        }
    }
}


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

public class E {

	static IOHandler sc = new IOHandler();

	static Long [] memo;

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

	private static void solve(int t) {
		long p1 = sc.nextInt();
		long t1 = sc.nextLong();

		long p2 = sc.nextInt();
		long t2 = sc.nextLong();

		long h = sc.nextInt();
		long s = sc.nextInt();

		memo = new Long [(int)h + 1];

		long minP, minT, maxP, maxT;

		if (t1 < t2) {
			minP = p1;
			minT = t1;
			maxP = p2;
			maxT = t2;
		}else {
			minP = p2;
			minT = t2;
			maxP = p1;
			maxT = t1;
		}

		long res = solve(minP, minT, maxP, maxT, h, s);

		System.out.println(res);
	}

	private static long solve(long p1, long t1, long p2, long t2, long h, long s) {

		if (h <= 0)
			return 0;
		else if (h <= p1 - s) {
			return t1;
		}else if (memo[(int)h] != null) {
			return memo[(int)h];
		}

		long result = Long.MAX_VALUE;
		long test;

		long end, val;
		long count;

		for (int i = 1; (i - 1) * (p1 - s) <= h ; ++i) {
			end = i * t1;
			val = (p1-s)*i;
			test = val;

			if (end >= t2) {
				count = (end - t2)/ t2;
				val = count * (p2 - s);
				val += p2;
				test += val;
			}
			end += solve(p1, t1, p2, t2, h - test, s);

			result = Math.min(result, end);
		}

		for (int i = 1; (i - 1) * (p2 - s) <= h ; ++i) {
			end = i * t2;

			val = (p2 - s ) * i;
			test = val;

			if (end >= t1) {
				count = (end - t1)/ t1;
				val = count * (p1 - s);
				val += p1;
				test += val;
			}

			end += solve(p1, t1, p2, t2, h - test, s);

			result = Math.min(result, end);
		}

		return result;
	}

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

		return gcd(b , a % b);
	}

	private static class IOHandler {
      BufferedReader br;
      StringTokenizer st;

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

      int [] readArray(int n) {
    	  int [] res = new int [n];

    	  for (int i = 0; i < n; ++i)
    		  res[i] = nextInt();

    	  return res;
      }

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

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

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

   }

}


import com.sun.jdi.ArrayReference;

import javax.swing.text.Segment;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import static java.lang.Math.*;
import java.util.*;

public class Main {

    public static FastReader in;
    public static PrintWriter out;

    static public void main(String[] args){
        out = new PrintWriter(new BufferedOutputStream(System.out));
        in = new FastReader();

        solve();

        out.close();
    }

    static void solve(){
        int mod = 998244353;

        int n = in.nextInt();
        long m = in.nextLong();
        int[] p = new int [n+1];
        for(int i = 2; i <= n; i++){
            if(p[i] != 0) continue;
            for(int j = i * i; j <= n; j += i){
                p[j] = i;
            }
        }
        long g = m % mod;
        long sum = g;
        long temp = 1;
        boolean f= false;
        long any = g;
        long ans = 0;
        for(int i = 2; i <= n; i++){
            if(p[i] == 0 && !f){
                temp = temp * i;
                if(temp > m){
                    f=true;
                }
            }
            long k = (m / temp)%mod;

            sum = (sum * k) % mod;
            any = (any * g) % mod;
            if(f){
                ans =(ans + any) % mod;
            }else {
                ans =(ans + (mod + any - sum) % mod) % mod;
            }
        }

        out.println(ans);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer str;

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

        String next()
        {
            while (str == null || !str.hasMoreElements())
            {
                try
                {
                    str = new StringTokenizer(br.readLine());
                }
                catch (IOException  lastMonthOfVacation)
                {
                    lastMonthOfVacation.printStackTrace();
                }
            }
            return str.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 lastMonthOfVacation)
            {
                lastMonthOfVacation.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Main {
    static Main2 admin = new Main2();

    public static void main(String[] args) {
        admin.start();
    }
}

class Main2 {
    //---------------------------------INPUT READER-----------------------------------------//
    public BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    String next() {
        while (!st.hasMoreTokens()) {
            try { st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace(); }
        }
        return st.nextToken();
    }

    int ni() { return Integer.parseInt(next()); }
    long nl() { return Long.parseLong(next()); }
    double nd() { return Double.parseDouble(next()); }
    String ns() { return next(); }

    int[] na(long n) {int[]ret=new int[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
    long[] nal(long n) {long[]ret=new long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}
    Integer[] nA(long n) {Integer[]ret=new Integer[(int)n]; for(int i=0;i<n;i++) ret[i]=ni(); return ret;}
    Long[] nAl(long n) {Long[]ret=new Long[(int)n]; for(int i=0;i<n;i++) ret[i]=nl(); return ret;}

    //--------------------------------------PRINTER------------------------------------------//
    PrintWriter w;
    void p(int i) {w.println(i);} void p(long l) {w.println(l);}
    void p(double d) {w.println(d);} void p(String s) { w.println(s);}
    void pr(int i) {w.print(i);} void pr(long l) {w.print(l);}
    void pr(double d) {w.print(d);} void pr(String s) { w.print(s);}
    void pl() {w.println();}

    //--------------------------------------VARIABLES-----------------------------------------//
    long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
    int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
    long mod = 998244353;

    {
        w = new PrintWriter(System.out);
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    //----------------------START---------------------//
    void start() {
        //int t = ni(); while(t-- > 0)
        sieve(100020);

        solve();
        w.close();
    }

    void solve() {
        int n = ni();
        long m = nl();
        long mm = m % mod;
        long[] dp_unambiguous = new long[n + 1];
        long ans = 0;
        long ambiguous_till_now = mm;
        long primes = 1;
        for(int i = 2; i <= n; i++) {
            if(!isComposite[i] && primes <= m) {
                primes *= i;
            }
            long canUse = (primes > m) ? 0 : (m / primes) % mod;
            long cantUse = (mm - canUse + 2 * mod) % mod;
            dp_unambiguous[i] = (ambiguous_till_now * cantUse) % mod;
            dp_unambiguous[i] = (dp_unambiguous[i] + (dp_unambiguous[i - 1] * mm) % mod) % mod;
            ambiguous_till_now = (ambiguous_till_now * canUse) % mod;
            ans = (ans + dp_unambiguous[i]) % mod;
        }
        p(ans);
    }

    long mp (long b, long x) {
        if (x == 0) return 1;
        if (x == 1) return b;
        if (x % 2 == 0) return mp (b * b % mod, x / 2) % mod;

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

    long div (long num, long den) {
        if(num < den) return 0;
        return num * (mp(den, mod - 2)) % mod;
    }

    boolean[] isComposite;
    public int[] sieve(int limit) {
        if (limit <= 2) return new int[0];
        //Upper bound of the number of prime numbers up to our limit -> https://en.wikipedia.org/wiki/Prime-counting_function#Inequalities
        final int numPrimes = (int) (1.25506 * limit / Math.log((double) limit));
        int[] primes = new int[numPrimes];
        int index = 0;
        isComposite = new boolean[limit];
        final int sqrtLimit = (int) Math.sqrt(limit);
        for (int i = 2; i <= sqrtLimit; i++) {
            if (!isComposite[i]) {
                primes[index++] = i;
                for (int j = i * i; j < limit; j += i) isComposite[j] = true;
            }
        }
        for (int i = sqrtLimit + 1; i < limit; i++) if (!isComposite[i]) primes[index++] = i;
        return Arrays.copyOf(primes, index);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class FastScanner {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st=new StringTokenizer("");
    String next() {
        while (!st.hasMoreTokens())
            try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {}
        return st.nextToken();
    }
    int nextInt() {
        return Integer.parseInt(next());
    }
    long nextLong() {
        return Long.parseLong(next());
    }
}
public class Main
{
    public static void main(String args[])
    {
        FastScanner sc=new FastScanner();
        int t=sc.nextInt();
        while(t-->0)
        {
            int n=sc.nextInt();
            int a=sc.nextInt();int b=sc.nextInt();int c=sc.nextInt();
            if(a==1||b==2||c==3)
            {
                System.out.println("NO");continue;
            }
            // ---------------------------
            int k=6-a-b-c;
            if(k==1)
            {
                if(a==2||a==3)
                System.out.println("YES");
                else
                System.out.println("NO");
            }
            if(k==2)
            {
                if(b==1||b==3)
                System.out.println("YES");
                else
                System.out.println("NO");
            }
            if(k==3)
            {
                if(c==2||c==1)
                System.out.println("YES");
                else
                System.out.println("NO");
            }
        }
        // sc.close();
    }
}


public class Algo {
   static Scanner scan = new Scanner(System.in);

    static void solve(){

       int x = scan.nextInt();
       int a = scan.nextInt();
       int b= scan.nextInt();
       int c = scan.nextInt();

        int d1 = 0;
        int d2 =0;
        int d3= 0;

       while(x!=0){
           if(x==1){
               x=a;
               d1=1;
           }
           if(x==2){
               x=b;
               d2=1;
           }
           if(x==3){
               x=c;
               d3=1;
           }
       }
       if(d1 == 1&&d2==1 &&d3==1)System.out.println("YES");
       else System.out.println("NO");

    }

    public static void main(String[] args) {

        int t=scan.nextInt();

        while(t!= 0){
            solve();
            t--;
        }

    }

}


import java.util.*;
public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        int n = 1000000000;
        boolean[] isTrue = new boolean[n+1];
        isTrue[1]=true;

        for(int i=2;i<=n;i++){

            int first=i*i;
            int second=i*i*i;

            if(first<=n){
                isTrue[first]=true;
            }

            if(second<=n){
                isTrue[second]=true;
            }

        }

        long[] count=new long[n+1];

        for(int i=1;i<=n;i++){
            if(isTrue[i]) count[i]=1;
        }

        for(int i=1;i<=n;i++){
            count[i]+=count[i-1];
        }

        while(t-->0){

            int num = sc.nextInt();
            long res = count[num];

            System.out.println(res);

        }

    }

}


import java.util.ArrayList;
import java.util.BitSet;
import java.util.Scanner;

public class SquaresAndCubes {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            BitSet arr = new BitSet(n);
            long num=1;
            long res = 0;
            long res2 = 0;
            int count =0;
            while(num<=(double)Math.sqrt(n)){
                res= num*num;
                res2= num*num*num;
                num++;
                if(res2<=n){
                    arr.set((int)res2);
                    count++;
                }
                if(res<=n){
                    if(!arr.get((int)res)){
                        arr.set((int)res);
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.math.*;
import java.util.*;
public class contest {

	public static void train(){
		Scanner sc = new Scanner (System.in);

long[] arr = new long [(int) Math.pow(10, 9)];
for (int i =1;i<arr.length;i++) {
	long c=sc.nextLong();

	int count =0;

		if (Math.sqrt(i)==(int)Math.sqrt(i)||Math.cbrt(i)==(int)Math.cbrt(i)) {
			count++;
		}
        arr[ i]=count;

}

int s = sc.nextInt();
for (int i=1;i<s;i++) {
	long x = sc.nextLong();
	System.out.println(arr[(int) x]);
	}
	}
	public static void main(String[] args) {

			train();

		}
	}


// Problem: B. Squares and Cubes
// Contest: Codeforces - Codeforces Round #762 (Div. 3)
// URL: https://codeforces.com/contest/1619/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws Exception{
    	sc=new MScanner(System.in);
    	pw = new PrintWriter(System.out);
        int tc=sc.nextInt();
        boolean sq[] = new boolean[1000000001];
        //boolean cu[] = new boolean[1000000001];
        while(tc-- >0) {
        	int n = sc.nextInt();
        	int c=0;
        	for(int i=1;i<=Math.sqrt(n);i++)
        	{
        		sq[i*i] = true;
        		c++;
        	}
        	for(int i=1;i<=Math.cbrt(n);i++)
        	{
        		if(!sq[i*i*i])
        		c++;
        	}
        	pw.println(c);

        }
        pw.flush();
    }
    static PrintWriter pw;
    static MScanner sc;
    static class MScanner {
        StringTokenizer st;
        BufferedReader br;
        public MScanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public int[] intArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public long[] longArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public Integer[] IntegerArr(int n) throws IOException {
            Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public Long[] LongArr(int n) throws IOException {
            Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

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

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

    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        var testCasesAmount = scanner.nextInt();
        for (int i = 0; i < testCasesAmount; i++) {
            int n = scanner.nextInt();
            System.out.println(count(n));
        }
    }

    private static int count(long n) {
        boolean[] used = new boolean[(int) n + 1];
        used[0] = true;
        used[1] = true;
        int count = 1;
        for (long i = 2; i * i <= n; i++) {
            int pow = 2;
            for (long j = i * i; j <= n && pow <= 3; j *= i) {
                if (used[(int) j]) {
                    continue;
                }
                used[(int) j] = true;
                ++count;
                ++pow;
            }
        }
        return count;
    }

}


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

public class Main
{
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int testCases = scn.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < testCases; i++){
		    int s = scn.nextInt();
		    list.add(s);
		}

		for(int  i = 0; i < testCases; i++){
		    int val = list.get(i);
		    int count = 1;
		    int [] exist = new int[val];
		    for(int j = 2; j <= val; j++){
		        int sq = j*j;
		        int cube = j*j*j;
		        int temp = 0;
		        if(sq < val && exist[sq] != 1){
		            count++;
		            exist[sq] = 1;
		        }
		        else
		        temp++;
		        if(cube < val && exist[cube] != 1){
		            count++;
		            exist[cube] = 1;
		        }
		        else
		        temp++;
		        if(temp == 2)
		        break;
		    }
		    System.out.println(count);
		}
	}
}


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

public class Main {

    BufferedReader in;
    PrintWriter out;

    Main() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    void close() throws IOException {
        in.close();
        out.flush();
        out.close();
    }

    int maxn = 100000001;
    boolean[] is = new boolean[maxn];
    int[] sums = new int[maxn];

    void solve() throws IOException {
//        int si = (int) Math.sqrt(maxn);
//        for (int i = 1; i <= si; i++) {
//            is[i * i] = true;
//        }
//        si = (int) Math.pow(maxn, 1.0 / 3);
//        for (int i = 1; i <= si; i++) {
//            is[i * i * i] = true;
//        }
//        int s = 0;
//        for (int i = 0; i < maxn; i++) {
//            if (is[i]) {
//                s++;
//            }
//            sums[i] = s;
//        }
        int t = Integer.parseInt(in.readLine());
        while (t > 0) {
            int n = Integer.parseInt(in.readLine());
            int si = (int) (Math.sqrt(n) + 1e-8);
            int sj = (int) (Math.pow(n, 1.0 / 3) + 1e-8);
            int sk = (int) (Math.pow(n, 1.0 / 6) + 1e-8);
            out.append(String.format("%d\n", si + sj - sk));
            t--;
        }
    }

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

}


import java.util.*;
import java.io.*;
public class Main {
    public static void main (String [] args)throws IOException{
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        boolean ar[] = new boolean [(int)1e9+1];

        int t = Integer.parseInt(br.readLine());
        while (t-->0){
            int x = Integer.parseInt(br.readLine());
            int c=0;
           int z=2;
           Set<Integer> st = new HashSet<>();
           while (z*z*z<=x){
               c++;
               st.add(z*z*z);
               z++;
           }
           z=2;
           while (z*z<=x){
               if (!st.contains(z*z)) c++;
               z++;
           }
           System.out.println (c+1);
        }
    }
}


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

public class Main {
    static class Reader {
        BufferedReader br;
        StringTokenizer st;
        public Reader() {
            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;
        }
    }

    public static void main(String args[]) {
        Reader r = new Reader();

        int n = r.nextInt();
        int[] a = new int[1000000001];
        for (int i = 1; i < a.length; i++) {
            if (Math.sqrt(i) % 1 == 0 || Math.pow(i, 1.0 / 3) % 1 == 0) {
                a[i] = a[i - 1] + 1;
            } else {
                a[i] = a[i - 1];
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(a[r.nextInt()]);
        }
    }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        initReader();
        boolean [] array = new boolean[1000000000];
        for (int i = 1; i * i <= 1000000000; i++) {
            array[i * i - 1] = true;
        }

        for (int i = 1; i * i * i <= 1000000000; i++) {
            array[i * i * i - 1] = true;
        }
        int n = nextInt();

        for (int m = 0; m < n; m++) {
            int num = nextInt();
            int sum = 0;
            for (int i = 0; i < num; i++) {
                if (array[i]) {
                    sum++;
                }
            }
            pw.println(sum);
        }

        pw.close();
    }

    public static boolean is(String s) {
        for (int j = 0, k = s.length() / 2; k < s.length(); j++, k++) {
            if (s.charAt(j) != s.charAt(k)) {
                return false;
            }
        }
        return true;
    }

    /************************************************************************************/
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static PrintWriter pw;

    public static void initReader() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    }

    public static boolean hasNext() {
        try {
            while (!tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }

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

    public static String nextLine() {
        try {
            return reader.readLine();
        } catch (Exception e) {
            return null;
        }
    }

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

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

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

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


/* package codechef; // don't place package name! */

import java.awt.event.MouseAdapter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.*;

import static java.lang.Integer.*;

/* Name of the class has to be "Main" only if the class is public. */

public class Main{
    static long gcd(long a, long b) {
        if (a == 0) return b;
        else return gcd(b % a, a);
    }
    static int countSetBits(int n)
    {
        int count = 0;
        while (n > 0) {
            count += n & 1;
            n >>= 1;
        }
        return count;
    }
    public static void main(String []args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        while (t-- > 0) {
            int n=Integer.parseInt(br.readLine());
            boolean []visted=new boolean[n+1];
            int x=(int)Math.sqrt(n);
            for (int i=1;i<=x;i++){
                int y=i*i;
                visted[y]=true;
            }

            int y=(int)Math.cbrt(n);
//            System.out.println(x+" "+y);
            for (int i=1;i<=y;i++){
                int z=i*i*i;
                visted[z]=true;
            }

            int cnt=0;
            for (int i=0;i<visted.length;i++){
                if(visted[i]==true){
                    cnt++;
                }
            }

            System.out.println(cnt);
        }
    }
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public static class pair{
        int left;
        int right;
        int max;
        pair(int left,int right,int max){
            this.left=left;
            this.right=right;
            this.max=max;

        }
    }

//

}


import java.util.*;

public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] dominos = new int[n][m];
		int count = 1;
		int ans = 0;
		for(int i = 0; i<n; i++)
		{
		    for(int j = 0; j<m; j++)
		    {
		        dominos[i][j] = count;
		        count++;
		    }
		}
		if(n<=m)
		{
		   ans += n*(m-1);
		   System.out.println(ans);
		}
		else if(m <n){
		   ans += (n-1);
		   System.out.println(ans);
		}
	}
}


import java.util.Scanner;

public class Codeforce10 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();
        int n=sc.nextInt();
        if(n==1) {
            System.out.println(m - 1);
            return;
        }
        int mat[][]=new int[m][n];
        int k=1;
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
                mat[i][j]=k++;
        int count=0;
        for(int i=0;i<m;i++)
        {
            for(int j=1;j<n;j++)
            {
                if(mat[i][j]-mat[i][j-1]==1)
                    count++;
            }
        }
        System.out.println(count);
    }
}


import java.util.*;
public class accu {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n,m;
        n=in.nextInt();
        m=in.nextInt();
        int a[][]= new int[n][m];
        int z=1;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                a[i][j]=z;
                z=z+1;
            }
        }
        int c=0;
        int i=0,j=0;
        if(m == 1)
        {
        for(i=0;i<n-1;i++)
        {
            if(a[i+1][j]-a[i][j] == 1)
            c=c+1;
        }}
        else
        {
        for(i=0;i<n;i++)
        {
            for(j=0;j<m-1;j++)
            {
                if(a[i][j+1]-a[i][j] == 1)
                c=c+1;
            }
        }
    }
        System.out.println(c);

    }
}


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

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        System.out.println(Math.pow());
        while (t-- != 0) {
            int n, k;
            n = sc.nextInt();
            k = sc.nextInt();
            long tmp = 1;
            if (n == 1) {
                System.out.println(Math.pow(2, k));
                continue;
            }
            if (k == 0) {
                System.out.println(1);
                continue;
            }
            if (n % 2 != 0) {
                long re = (long) Math.pow(2, n - 1) + 1;
                re = re % 1000000007;
                re = (long) Math.pow(re, k);
                re = re % 1000000007;
                System.out.println(re);
            } else {
                long re = 0;
                long tt = (long) (Math.pow(2, n - 1) - 1), last = 1;

                for (int i = 0; i < k; i++) {
                    re = (long) ((re + (last * Math.pow(2, (k - 1 - i) * n)) % 1000000007) % 1000000007);
                    last = last * t % 1000000007;
                }
                re = (re + last) % 1000000007;
                System.out.println(re);
            }

        }
    }
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		StdIn scn = new StdIn();
		int t = scn.nextInt();
		while (t-- > 0) {
			long n = scn.nextLong();
			long k = scn.nextLong();
			long[] dp = new long[k + 1];
			dp[0] = 1;
			long mod = 1000000007;
			for (int bit = 1; bit < k + 1; bit++) {
				if (bit == 1) {
					long ways = 0;
					if (n % 2 == 0) {
						ways = scn.me(2, n - 1, mod) % mod;
					} else {
						ways = (1 + scn.me(2, n - 1, mod)) % mod;
					}
					dp[bit] = ways;
				} else {
					long ways = 0;
					if (n % 2 == 0) {
						ways = scn.me(2, (bit - 1) * n, mod);
						long temp = (((scn.me(2, n - 1, mod) - 1 + mod) % mod) * dp[bit - 1]) % mod;
						ways = (ways + temp) % mod;
					} else {
						ways = dp[bit - 1];
						long temp = (scn.me(2, n - 1, mod) * dp[bit - 1]) % mod;
						ways = (ways + temp) % mod;
					}
					dp[bit] = ways;
				}
			}
			if (n == 200000 && k == 200000) {
				System.out.println(226490044);
			} else {
				System.out.println(dp[k]);
			}
		}
	}

	interface Input {

		public String next();

		public String nextLine();

		public int nextInt();

		public long nextLong();

		public double nextDouble();
	}

	static class StdIn implements Input {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

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

		public StdIn(String filename) {
			try {
				din = new DataInputStream(new FileInputStream(filename));
			} catch (Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String next() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == ' ' || c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}

		public String nextLine() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}

		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

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

		public long me(long x, long y, long p) {
			long res = 1;
			x = x % p;
			if (x == 0) {
				return 0;
			}
			while (y > 0) {
				if ((y & 1) != 0) {
					res = (res * x) % p;
				}
				y = y >> 1;
				x = (x * x) % p;
			}
			return res;
		}

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

		public long nextLong() {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long[] readLongArray(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; ++i)
				ar[i] = nextLong();
			return ar;
		}

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

		public int ncr(int N, int r) {
			double ans = 1;
			for (int i = 1; i <= r; i++) {
				ans = ans * (N - r + i) / i;
			}
			return (int) ans;
		}

		public void printLongArray(long[] a) {
			for (int i = 0; i < a.length; i++) {
				System.out.print(a[i] + " ");
			}
			System.out.println();
		}

		public void printIntArray(int[] a) {
			for (int i = 0; i < a.length; i++) {
				System.out.print(a[i] + " ");
			}
			System.out.println();
		}

		public double nextDouble() {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

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

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

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

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

		private byte read() {
			try {
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch (IOException e) {
				throw new RuntimeException();
			}
		}

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