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

class Main
{
	public static int k, d, quantity = 0;
	public static long[] was = new long[40320];
	public static long[] nums = new long[9];
	public static boolean Was(long h) {
    	long c = 0;
    	for (int i = 0; i < quantity; i++) {
        	if (was[i] == h) c++;
    	}
    	if (c == 0) {
        	was[quantity] = h;
        	return true; 
    	}
    	else
    	return false;
	}
	public static void Swap(int a, int b) {
    	long t = nums[a];
    	nums[a] = nums[b];
    	nums[b] = t;
	}
	public static void Generate(int n) {
	    if (n == k) {
	        long sum = 0;
	        long p = 1;
	        long h = 0;
	        long hash = 1;
	        for (int i = k - 1; i >= 0; i--) {
	            long subs = nums[i];
	            sum += nums[i] % d * p;
	            p *= Math.pow(10, (long)Math.log10(nums[i]) + 1);
	            p = p % d;
	            while (subs!= 0) {
	                h += subs % 10 * hash;
	                hash *= 101;
	                subs /= 10;
	            }
	        }   
	        if (sum%d == 0 && Was(h) == true) {
	            quantity++; 
	        }
	    }
	    else { 
	        for(int j = n; j < k;j++) {
	            Swap(n,j);
	            Generate(n+1);
	            Swap(n,j);
	        }
	    }   
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		d = in.nextInt();
		k = in.nextInt();
    	for(int i = 0; i < k; i++) {
    		nums[i] = in.nextLong();
    	}
    	Generate(0);
    	System.out.println(quantity);
	}
}