#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
long long nums[9];
long long k;
long long d;
long long quantity = 0;
long long was[40320];
bool Was(long long h) {
long 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;
}
void Swap(long long a,long long b)
{
long long t = nums[a];
nums[a] = nums[b];
nums[b] = t;
}
void Generate(long long n)
{
if (n==k)
{
long long sum = 0;
long long p = 1;
long long h = 0;
long long hash = 1;
for (long long i = k - 1; i >= 0; i--) {
long long subs = nums[i];
sum += nums[i]%d*p;
p *= pow(10, long(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(long long j = n; j < k;j++) {
Swap(n,j);
Generate(n+1);
Swap(n,j);
}
}
}
int main()
{
cin >> d >> k;
for(long long i = 0; i < k; i++) {
cin >> nums[i];
}
Generate(0);
cout << quantity;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmxvbmcgbG9uZyBudW1zWzldOwpsb25nIGxvbmcgazsKbG9uZyBsb25nIGQ7CmxvbmcgbG9uZyBxdWFudGl0eSA9IDA7CmxvbmcgbG9uZyB3YXNbNDAzMjBdOwpib29sIFdhcyhsb25nIGxvbmcgaCkgewoJbG9uZyBsb25nIGMgPSAwOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBxdWFudGl0eTsgaSsrKSB7CgkJaWYgKHdhc1tpXSA9PSBoKSBjKys7Cgl9CglpZiAoYyA9PSAwKSB7CgkJd2FzW3F1YW50aXR5XSA9IGg7CgkJcmV0dXJuIHRydWU7IAoJfQoJZWxzZQoJcmV0dXJuIGZhbHNlOwp9CnZvaWQgU3dhcChsb25nIGxvbmcgYSxsb25nIGxvbm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