#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, k, dp[N][26];
char s[N];
bool vis[26][26];
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    char c[3];
    scanf("%s", c);
    vis[c[0] - 'a'][c[1] - 'a'] = vis[c[1] - 'a'][c[0] - 'a'] = 1;
  }
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < 26; i++) dp[0][i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 26; j++) {
      if (j == s[i] - 'a') {
        for (int k = 0; k < 26; k++)
          if (!vis[j][k]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][k]);
      } else
        dp[i + 1][j] = dp[i][j] + 1;
    }
  int ret = inf;
  for (int i = 0; i < 26; i++) ret = min(ret, dp[n][i]);
  printf("%d\n", ret);
  return 0;
}
