#include <bits/stdc++.h>
using namespace std;
char use[100010];
int unable[30][30];
int dp[100010][30];
int main() {
  scanf("%s", &use);
  int k;
  scanf("%d", &k);
  memset(unable, 0, sizeof(unable));
  for (int i = 0; i < k; i++) {
    char tmp[5];
    scanf("%s", tmp);
    unable[tmp[0] - 'a'][tmp[1] - 'a'] = 1;
    unable[tmp[1] - 'a'][tmp[0] - 'a'] = 1;
  }
  int n = strlen(use);
  for (int i = 0; i < n; i++) use[i] -= 'a';
  memset(dp, 0x3f, sizeof(dp));
  for (int j = 0; j < 26; j++) dp[0][j] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (!unable[j][use[i]]) {
        dp[i + 1][use[i]] = min(dp[i + 1][use[i]], dp[i][j]);
      }
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
    }
  }
  int ret = 0x3f3f3f3f;
  for (int j = 0; j < 26; j++) ret = min(dp[n][j], ret);
  printf("%d\n", ret);
}
