#include <bits/stdc++.h>
template <typename Tp>
Tp Max(const Tp &a, const Tp &b) {
  return a > b ? a : b;
}
template <typename Tp>
Tp Min(const Tp &a, const Tp &b) {
  return a < b ? a : b;
}
template <typename Tp>
void Read(Tp &x) {
  Tp in = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    in = in * 10 + ch - '0';
    ch = getchar();
  }
  x = in * f;
}
const int SN = 100000 + 10;
int n, k;
char s[SN];
char node[SN][3];
int vis[100][100];
int f[SN][30];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  Read(k);
  for (int i = 1; i <= k; i++)
    scanf("%s", node[i] + 1),
        vis[node[i][1] - 'a'][node[i][2] - 'a'] = 1,
                                           vis[node[i][2] - 'a']
                                              [node[i][1] - 'a'] = 1;
  memset(f, 0x3f, sizeof f);
  f[0][26] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 26; j++) {
      int now = s[i] - 'a';
      if (f[i - 1][j] == f[0][0]) continue;
      f[i][j] = Min(f[i][j], f[i - 1][j] + 1);
      if (!vis[j][now]) f[i][now] = Min(f[i][now], f[i - 1][j]);
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i <= 26; i++) ans = Min(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
