#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int dp[maxn + 100][27];
int n, k;
char second[maxn + 100];
bool a[27][27];
int calc(int p, int last) {
  if (p == n) return 0;
  if (dp[p][last] != -1) return dp[p][last];
  int &res = dp[p][last];
  res = calc(p + 1, last) + 1;
  if (a[last][second[p] - 'a']) res = min(res, calc(p + 1, second[p] - 'a'));
  return res;
}
int main() {
  gets(second);
  n = strlen(second);
  memset(a, 1, sizeof(a));
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string second;
    cin >> second;
    a[second[0] - 'a'][second[1] - 'a'] = false;
    a[second[1] - 'a'][second[0] - 'a'] = false;
  }
  memset(dp, -1, sizeof(dp));
  int res = calc(0, 26);
  printf("%d\n", res);
  return 0;
}
