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);
}
}
}
{
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);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBNYWluCnsKCXB1YmxpYyBzdGF0aWMgaW50IGssIGQsIHF1YW50aXR5ID0gMDsKCXB1YmxpYyBzdGF0aWMgbG9uZ1tdIHdhcyA9IG5ldyBsb25nWzQwMzIwXTsKCXB1YmxpYyBzdGF0aWMgbG9uZ1tdIG51bXMgPSBuZXcgbG9uZ1s5XTsKCXB1YmxpYyBzdGF0aWMgYm9vbGVhbiBXYXMobG9uZyBoKSB7CiAgICAJbG9uZyBjID0gMDsKICAgIAlmb3IgKGludCBpID0gMDsgaSA8IHF1YW50aXR5OyBpKyspIHsKICAgICAgICAJaWYgKHdhc1tpXSA9PSBoKSBjKys7CiAgICAJfQogICAgCWlmIChjID09IDApIHsKICAgICAgICAJd2FzW3F1YW50aXR5XSA9IGg7CiAgICAgICAgCXJldHVybiB0cnVlOyAKICAgIAl9CiAgICAJZWxzZQogICAgCXJldHVybiBmYWxzZTsKCX0KCXB1YmxpYyBzdGF0aWMgdm9pZCBTd2FwKGludCBhLCBpbnQgYikgewogICAgCWxvbmcgdCA9IG51bXNbYV07CiAgICAJbnVtc1thXSA9IG51bXNbYl07CiAgICAJbnVtc1tiXSA9IHQ7Cgl9CglwdWJsaWMgc3RhdGljIHZvaWQgR2VuZXJhdGUoaW50IG4pIHsKCSAgICBpZiAobiA9PSBrKSB7CgkgICAgICAgIGxvbmcgc3VtID0gMDsKCSAgICAgICAgbG9uZyBwID0gMTsKCSAgICAgICAgbG9uZyBoID0gMDsKCSAgICAgICAgbG9uZyBoYXNoID0gMTsKCSAgICAgICAgZm9yIChpbnQgaSA9IGsgLSAxOyBpID49IDA7IGktLSkgewoJICAgICAgICAgICAgbG9uZyBzdWJzID0gbnVtc1tpXTsKCSAgICAgICAgICAgIHN1bSArPSBudW1zW2ldICUgZCAqIHA7CgkgICAgICAgICAgICBwICo9IE1hdGgucG93KDEwLCAobG9uZylNYXRoLmxvZzEwKG51bXNbaV0pICsgMSk7CgkgICAgICAgICAgICBwID0gcCAlIGQ7CgkgICAgICAgICAgICB3aGlsZSAoc3VicyE9IDApIHsKCSAgICAgICAgICAgICAgICBoICs9IHN1YnMgJSAxMCAqIGhhc2g7CgkgICAgICAgICAgICAgICAgaGFzaCAqPSAxMDE7CgkgICAgICAgICAgICAgICAgc3VicyAvPSAxMDsKCSAgICAgICAgICAgIH0KCSAgICAgICAgfSAgIAoJICAgICAgICBpZiAoc3VtJWQgPT0gMCAmJiBXYXMoaCkgPT0gdHJ1ZSkgewoJICAgICAgICAgICAgcXVhbnRpdHkrKzsgCgkgICAgICAgIH0KCSAgICB9CgkgICAgZWxzZSB7IAoJICAgICAgICBmb3IoaW50IGogPSBuOyBqIDwgaztqKyspIHsKCSAgICAgICAgICAgIFN3YXAobixqKTsKCSAgICAgICAgICAgIEdlbmVyYXRlKG4rMSk7CgkgICAgICAgICAgICBTd2FwKG4saik7CgkgICAgICAgIH0KCSAgICB9ICAgCgl9CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTY2FubmVyIGluID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCQlkID0gaW4ubmV4dEludCgpOwoJCWsgPSBpbi5uZXh0SW50KCk7CiAgICAJZm9yKGludCBpID0gMDsgaSA8IGs7IGkrKykgewogICAgCQludW1zW2ldID0gaW4ubmV4dExvbmcoKTsKICAgIAl9CiAgICAJR2VuZXJhdGUoMCk7CiAgICAJU3lzdGVtLm91dC5wcmludGxuKHF1YW50aXR5KTsKCX0KfQ==