#include <bits/stdc++.h>
using namespace std;
string str;
bool forbid[32][32], letter_forbid[32];
int dp[32][100001];
int recur(int letter, int cur) {
  if (cur >= int(str.size())) return 0;
  if (dp[letter][cur] >= 0) return dp[letter][cur];
  int c = str[cur] - 'a';
  if (!letter_forbid[c]) return dp[letter][cur] = recur(c, cur + 1);
  if (forbid[letter][c]) return dp[letter][cur] = 1 + recur(letter, cur + 1);
  int no_remove = recur(c, cur + 1);
  int remove = 1 + recur(letter, cur + 1);
  return dp[letter][cur] = min(no_remove, remove);
}
int main(int narg, char **arg) {
  memset(dp, -1, sizeof(dp));
  int n;
  string pair_forbid;
  cin >> str >> n;
  for (int i = 0; i < n; i++) {
    cin >> pair_forbid;
    forbid[pair_forbid[0] - 'a'][pair_forbid[1] - 'a'] = true;
    forbid[pair_forbid[1] - 'a'][pair_forbid[0] - 'a'] = true;
    letter_forbid[pair_forbid[0] - 'a'] = true;
    letter_forbid[pair_forbid[1] - 'a'] = true;
  }
  cout << recur(31, 0) << endl;
  return 0;
}
