#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5;
const int ALPH = 26;
char s[MAXN + 1];
bool bad[ALPH + 1][ALPH + 1];
int memo[MAXN][ALPH + 1], N;
int calc(int i, int pos) {
  if (i == N) return 0;
  if (memo[i][pos] != -1) return memo[i][pos];
  int ret = calc(i + 1, pos) + 1;
  if (!bad[pos][s[i] - 'a']) {
    ret =
        ((ret) < (calc(i + 1, s[i] - 'a')) ? (ret) : (calc(i + 1, s[i] - 'a')));
  }
  return memo[i][pos] = ret;
}
int main(void) {
  scanf("%s", s);
  N = strlen(s);
  memset(memo, -1, sizeof(memo));
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    char c1, c2;
    scanf(" %c %c", &c1, &c2);
    bad[c1 - 'a'][c2 - 'a'] = 1;
    bad[c2 - 'a'][c1 - 'a'] = 1;
  }
  printf("%d\n", calc(0, 26));
  return 0;
}
