#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string word;
vector <int> D(256), U;
int n;
for (int i = 0; i < D.size(); i++) D[i] = 0;
cin >> word; // ввод заданного слова;
for (int i = 0; i < word.size(); i++)
{
D[word[i]+127]++;
}
cin >> n; // ввод количество слов, которые можно составить из заданного слова;
int rez = 0;
for (int i = 0; i < n; i++)
{
cin >> word; // ввод слов со словаря;
U = D;
bool words = true;
for (int j = 0; j < word.size(); j++)
{
U[word[j]+127]--;
if (U[word[j]+127] < 0)
{
words = false;
break;
}
}
rez += words;
}
cout << rez << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCkgewoJc3RyaW5nIHdvcmQ7IAoJdmVjdG9yIDxpbnQ+IEQoMjU2KSwgVTsKCWludCBuOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBELnNpemUoKTsgaSsrKSBEW2ldID0gMDsKIAoJY2luID4+IHdvcmQ7IC8vINCy0LLQvtC0INC30LDQtNCw0L3QvdC+0LPQviDRgdC70L7QstCwOwoJZm9yIChpbnQgaSA9IDA7IGkgPCB3b3JkLnNpemUoKTsgaSsrKSAKCXsgCgkJRFt3b3JkW2ldKzEyN10rKzsKCX0KIAoJY2luID4+IG47IC8vINCy0LLQvtC0INC60L7Qu9C40YfQtdGB0YLQstC+INGB0LvQvtCyLCDQutC+0YLQvtGA0YvQtSDQvNC+0LbQvdC+INGB0L7RgdGC0LDQstC40YLRjCDQuNC3INC30LDQtNCw0L3QvdC+0LPQviDRgdC70L7QstCwOwogCglpbnQgcmV6ID0gMDsgIAoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIAoJewoJCWNpbiA+PiB3b3JkOyAvLyDQstCy0L7QtCDRgdC70L7QsiDRgdC+INGB0LvQvtCy0LDRgNGPOwogCgkJVSA9IEQ7CiAKCQlib29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