#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 2;
int flag[27][27];
int dp[100010][27];
char s[100010];
int main() {
  int k;
  string op;
  while (scanf("%s", s + 1) != EOF) {
    cin >> k;
    memset(flag, 0, sizeof(flag));
    fill(dp[0], dp[100001], inf);
    while (k--) {
      cin >> op;
      flag[op[0] - 'a'][op[1] - 'a'] = 1;
      flag[op[1] - 'a'][op[0] - 'a'] = 1;
    }
    dp[0][26] = 0;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) {
      for (int j = 0; j <= 26; j++)
        if (dp[i - 1][j] != inf) {
          int k = s[i] - 'a';
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
          if (!flag[j][k]) {
            dp[i][k] = min(dp[i][k], dp[i - 1][j]);
          }
        }
    }
    int ans = inf;
    for (int i = 0; i <= 26; i++) {
      if (dp[len][i] < ans) {
        ans = dp[len][i];
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
