#include <bits/stdc++.h>
using namespace std;
int f[26];
char s[100005];
int dp[100005][26];
int main(void) {
  int n;
  scanf("%s", s + 1);
  scanf("%d", &n);
  for (int i = 0; i < 26; i++) f[i] = -1;
  for (int i = 0; i < n; i++) {
    char x[10];
    scanf("%s", x);
    f[x[0] - 'a'] = x[1] - 'a';
    f[x[1] - 'a'] = x[0] - 'a';
  }
  for (int i = 1; s[i]; i++) {
    int mins = 1 << 20;
    for (int j = 0; j < 26; j++)
      if (j != f[s[i] - 'a']) mins = min(dp[i - 1][j], mins);
    for (int j = 0; j < 26; j++) {
      if (j == s[i] - 'a') {
        dp[i][j] = mins;
      } else {
        dp[i][j] = dp[i - 1][j] + 1;
      }
    }
  }
  int m = strlen(s + 1);
  printf("%d\n", *min_element(dp[m], dp[m] + 26));
  return 0;
}
