#include <bits/stdc++.h>
using namespace std;
char a[150000];
int bid[300][300];
int dp[150000];
int temp[300];
int main() {
  while (~scanf("%s", a + 1)) {
    int n = strlen(a + 1);
    memset(dp, 0, sizeof(dp));
    memset(temp, 0, sizeof(temp));
    memset(bid, 0, sizeof(bid));
    int k;
    scanf("%d", &k);
    while (k--) {
      char b[45];
      scanf("%s", b);
      bid[b[0]][b[1]] = 1;
      bid[b[1]][b[0]] = 1;
    }
    int output = 0;
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        dp[i] = 1;
        temp[a[i]] = 1;
      } else {
        for (int j = 'a'; j <= 'z'; j++) {
          if (bid[a[i]][j] == 0) {
            dp[i] = max(dp[i], temp[j] + 1);
          }
        }
        temp[a[i]] = max(temp[a[i]], dp[i]);
      }
      output = max(output, dp[i]);
    }
    printf("%d\n", n - output);
  }
}
