import java.io.*; import java.util.*; public class Main { static int count; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); makeAns(0, sc.next().toCharArray(), 0, 0); System.out.println(count); } static void makeAns(int idx, char[] string, long value, long total) { if (idx >= string.length) { if (isPrime(value + total)) { count++; } return; } makeAns(idx + 1, string, string[idx] - '0', value + total); if (idx > 0) { makeAns(idx + 1, string, value * 10 + string[idx] - '0', total); } } static boolean isPrime(long x) { if (x < 2) { return false; } for (long i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }