#include <bits/stdc++.h>
using namespace std;
int pairno[1502] = {-1};
int main() {
  char str[1000502], str1[23][5];
  int n, l, ans = 0;
  scanf("%s", str);
  scanf("%d", &n);
  l = strlen(str);
  for (int i = 0; i < 500; i++) pairno[i] = -1;
  while (n--) {
    scanf("%s", str1[n]);
    pairno[str1[n][0]] = n;
    pairno[str1[n][1]] = n;
  }
  int y1 = 0, y0 = 0, x1 = 0, x2 = 0, prevpair = -1;
  for (int i = 0; i < l; i++) {
    if (pairno[str[i]] == -1) {
      ans += min(y1, y0);
      prevpair = -1;
      y0 = 0;
      y1 = 0;
    } else if (pairno[str[i]] != prevpair) {
      ans += min(y1, y0);
      prevpair = pairno[str[i]];
      y1 = 0;
      y0 = 0;
      if (str[i] == str1[pairno[str[i]]][0])
        y0++;
      else
        y1++;
    } else {
      if (str[i] == str1[pairno[str[i]]][0])
        y0++;
      else
        y1++;
    }
  }
  ans += min(y1, y0);
  printf("%d\n", ans);
}
