#include <bits/stdc++.h>
using namespace std;
int n, k;
char s[100005];
char p[15][2];
int b0, b1;
int res;
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) scanf("%s", p[i]);
  int d, c;
  for (int i = 0; i < n; ++i) {
    bool found = false;
    for (int j = 0; j < k; ++j) {
      if (s[i] == p[j][0] || s[i] == p[j][1]) {
        d = j;
        found = true;
        break;
      }
    }
    if (found) {
      b0 = b1 = 0;
      int j;
      for (j = i; s[j] == p[d][0] || s[j] == p[d][1]; ++j) {
        if (s[j] == p[d][0])
          b0++;
        else
          b1++;
      }
      res += min(b0, b1);
      i = j - 1;
    }
  }
  printf("%d\n", res);
}
