public static void main(String[] args)
	{
		HashSet<HashSet<Integer>> primeSets = new HashSet<HashSet<Integer>>();
		ArrayList<Integer> nums = new ArrayList<Integer>();
		for (int i = 1; i < 10; i++)
			nums.add(i);
		ArrayList<ArrayList<Integer>> perms = perms(nums);
		for (int i = 0; i < perms.size(); i++)
		{
			ArrayList<Integer> currentPerm = perms.get(i);
			for (int j = 0; j < 256; j++)
			{
				String divider = toBinaryString(j, 8);
				HashSet<Integer> currentSet = new HashSet<Integer>();
				boolean allPrime = true;
				int current = currentPerm.get(0);
				for (int k = 1; k < 9 && allPrime; k++)
				{
					if (divider.charAt(k-1) == '0')
					{
						current *= 10;
						current += currentPerm.get(k);
					}
					else
					{
						if (isPrime(current))
							currentSet.add(current);
						else
							allPrime = false;
						current = currentPerm.get(k);
					}
				}
				if (allPrime && isPrime(current))
				{
					currentSet.add(current);
					primeSets.add(currentSet);
				}
			}
		}
		System.out.println(primeSets.size());	
	}