#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
char bad['z' + 1];
int maxlen['z' + 1];
char cad[100000 + 10];
int N;
int main() {
  memset(bad, 0, sizeof(bad));
  scanf("%s", cad);
  N = strlen(cad);
  int E;
  scanf("%d", &E);
  for (int i = 0, _n = E; i < _n; i++) {
    char s[10];
    scanf("%s", s);
    bad[s[0]] = s[1];
    bad[s[1]] = s[0];
  }
  memset(maxlen, 0, sizeof(maxlen));
  for (int i = 0, _n = N; i < _n; i++) {
    int best = 0;
    for (int c = 'a'; c <= 'z'; c++) {
      if (bad[cad[i]] != c) {
        best = max(best, maxlen[c]);
      }
    }
    maxlen[cad[i]] = best + 1;
  }
  int best = 0;
  for (int c = 'a'; c <= 'z'; c++) best = max(best, maxlen[c]);
  printf("%d\n", N - best);
}
