#include <bits/stdc++.h>
int k, len;
char str[100010];
char fo[20][20];
int ans;
int vis[100010];
int main(void) {
  scanf("%s", str);
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) scanf("%s", fo[i]);
  while (str[len] != '\0') ++len;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < len; ++j) {
      if (str[j] == fo[i][0]) vis[j] = 1;
      if (str[j] == fo[i][1]) vis[j] = 2;
    }
    for (int j = 0, c1 = 0, c2 = 0; j <= len; ++j) {
      if (vis[j] == 0) {
        ans += std::min(c1, c2);
        c1 = c2 = 0;
        continue;
      }
      if (vis[j] == 1) c1++;
      if (vis[j] == 2) c2++;
    }
    for (int j = 0; j < len; ++j) vis[j] = 0;
  }
  printf("%d\n", ans);
  return 0;
}
