#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int f[100005][26];
int main() {
  char str[100005], ch[3];
  bool can[26][26];
  int inf = 100000;
  while (scanf("%s", str) == 1) {
    int i, j;
    scanf("%d", &j);
    memset(can, 0, sizeof can);
    while (j--) {
      scanf("%s", ch);
      can[ch[0] - 'a'][ch[1] - 'a'] = can[ch[1] - 'a'][ch[0] - 'a'] = 1;
    }
    for (i = 0; i < 26; i++) f[0][i] = inf;
    f[0][str[0] - 'a'] = 0;
    for (i = 1; str[i]; i++) {
      for (j = 0; j < 26; j++) f[i][j] = f[i - 1][j] + 1;
      f[i][str[i] - 'a'] = min(i, f[i][str[i] - 'a']);
      for (j = 0; j < 26; j++)
        if (!can[str[i] - 'a'][j])
          f[i][str[i] - 'a'] = min(f[i - 1][j], f[i][str[i] - 'a']);
    }
    int ans = inf;
    for (--i, j = 0; j < 26; j++)
      if (f[i][j] < ans) ans = f[i][j];
    printf("%d\n", ans);
  }
  return 0;
}
