#include <bits/stdc++.h>
using namespace std;
char s[100005], ss[10];
int K, ct[2];
int main() {
  scanf("%s%d", s, &K);
  int n = strlen(s), ret = 0;
  for (int i = 0; i < K; i++) {
    scanf("%s", ss);
    ct[0] = ct[1] = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] != ss[0] && s[j] != ss[1]) {
        ret += min(ct[0], ct[1]);
        ct[0] = ct[1] = 0;
      }
      if (s[j] == ss[0]) ct[0]++;
      if (s[j] == ss[1]) ct[1]++;
    }
    ret += min(ct[0], ct[1]);
  }
  printf("%d\n", ret);
  return 0;
}
