#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
int read()
{
int a = 0,x = 1;char ch = getchar();
while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();}
while(ch >='0' && ch <= '9') {a = a*10 + ch-'0';ch = getchar();}
return a*x;
}
const int N = 1e6+7,base1 = 133,base2 = 131,mod1 = 1000429,mod2 = 20190631;
char s[N*5];
int head[N],go[N],nxt[N],cnt,val[N];
void add(int u,int v,int w)
{
go[++cnt] = v;
nxt[cnt] = head[u];
head[u] = cnt;
val[cnt] = w;
}
int fid(int u,int v)
{
for(int e = head[u];e;e = nxt[e]) {
if(go[e] == v) return e;
}
return 0;
}
int main()
{
// freopen("in.in","r",stdin);
gets(s+1);int len = strlen(s+1);s[len+1] = ' ';len ++;
ll hash1 = 0,hash2 = 0;
for(int i = 1;i <= len;i ++) {
if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 'a'-'A';
if(s[i] > 'z' || s[i] < 'a') {
if(hash1) {
int e = fid(hash1,hash2);
if(e) val[e] ++;
else {
add(hash1,hash2,1);
}
hash1 = hash2 = 0;
}
continue;
}
hash1 = (hash1 * base1 + s[i]) % mod1;
hash2 = (hash2 * base2 + s[i]) % mod2;
}
int n = read();
for(int i= 1;i <= n;i ++) {
scanf("%s",s+1);len = strlen(s+1);
hash1 = hash2 = 0;
for(int j = 1;j <= len;j ++) {
hash1 = (hash1 * base1 + s[j]) % mod1;
hash2 = (hash2 * base2 + s[j]) % mod2;
}
int e = fid(hash1,hash2);
val[e] = 0;
}
int ans = 0;
for(int i = 1;i <= cnt;i ++) ans += val[i];
printf("%d\n",ans);
}