// Arup Guha
// 3/29/2025
// Solution to Kattis Problem: Grid Magic

import java.util.*;

public class gridmagic {

	public static HashSet<Integer> primes;
	
	public static int[][] grid;
	public static int[][] rowVal;
	public static int[][] colVal;
	public static int r;
	public static int c;
	
	public static void main(String[] args) {

		// Generate all prefix primes.
		primes = new HashSet<Integer>();
		go(0);
		
		// Read input.
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		
		// Allocate arrays.
		grid = new int[r][c];
		rowVal = new int[r][c];
		colVal = new int[r][c];
		
		// Solve it.
		System.out.println(solve(0));
	}
	
	// Returns # of solutions with this grid with the first k items filled in.
	public static int solve(int k) {
		
		// We made it.
		if (k == r*c) return 1;
		
		// x is current row, y is current column.
		int x = k/c;
		int y = k%c;
		
		int res = 0;
		
		// Try each digit in slot k.
		for (int i=0; i<10; i++) {
			
			// See if we can add digit i in this slot.
			if (okay(x, y, i)) {
				
				// Put it in, update our cumulative values and recurse.
				grid[x][y] = i;
				rowVal[x][y] = y == 0 ? i : 10*rowVal[x][y-1]+i;
				colVal[x][y] = x == 0 ? i : 10*colVal[x-1][y]+i;
				res += solve(k+1);
			}
		}
		
		// Ta da!
		return res;
	}
	
	// Returns true iff placing d in row x and column y is valid.
	public static boolean okay(int x, int y, int d) {
		
		// New number on this row.
		int val = y == 0 ? d : 10*rowVal[x][y-1] + d;
		
		// If this new number isn't prime it's not okay.
		if (!primes.contains(val)) return false;
		
		// Do same for column,
		val = x == 0 ? d : 10*colVal[x-1][y] + d;
		if (!primes.contains(val)) return false;
		
		// If we get here, we're good.
		return true;
	}
	
	// Generates and stores all primes with prefix cur.
	public static void go(int cur) {
		
		// Add it except for 0.
		if (cur > 0)
			primes.add(cur);
		
		// Try each digit after cur and recurse if it's prime.
		for (int i=0; i<10; i++)
			if (10*cur+i > cur && isPrime(10*cur+i))
				go(10*cur+i);
	}
	
	// Usual prime check...
	public static boolean isPrime(int n) {
		if (n<2) return false;
		for (int i=2; i*i<=n; i++)
			if (n%i == 0)
				return false;
		return true;
	}
}