#include <bits/stdc++.h>
using namespace std;
char s[100005];
int dp[100005][30];
int mp[30][30];
int main() {
  while (scanf("%s", s) != EOF) {
    int n, i, j;
    scanf("%d", &n);
    memset(mp, 0, sizeof(mp));
    char p[4];
    for (i = 1; i <= n; i++) {
      scanf("%s", p);
      mp[p[0] - 'a'][p[1] - 'a'] = 1;
      mp[p[1] - 'a'][p[0] - 'a'] = 1;
    }
    memset(dp, 0x7f7f7f7f, sizeof(dp));
    dp[0][26] = 0;
    int l = strlen(s);
    for (i = 0; i < l; i++) {
      for (j = 0; j <= 26; j++) {
        if (dp[i][j] == 0x7f7f7f7f) continue;
        int id = s[i] - 'a';
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
        if (!mp[id][j]) dp[i + 1][id] = min(dp[i + 1][id], dp[i][j]);
      }
    }
    int ans = 0x7f7f7f7f;
    for (i = 0; i < 27; i++) ans = min(ans, dp[l][i]);
    printf("%d\n", ans);
  }
  return 0;
}
