#include <bits/stdc++.h>
using namespace std;
int INF = 999999999;
double EPSILON = 0.00000001;
int pairnum[30];
int main() {
  memset(pairnum, -1, sizeof(pairnum));
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string f;
    cin >> f;
    pairnum[f[0] - 'a'] = pairnum[f[1] - 'a'] = i;
  }
  int ans = 0;
  int i = 0;
  while (i < s.length()) {
    int j = i + 1;
    int a = 1;
    int b = 0;
    while (j < s.length() and pairnum[s[j] - 'a'] >= 0 and
           pairnum[s[j] - 'a'] == pairnum[s[i] - 'a']) {
      if (s[j] == s[i])
        a++;
      else
        b++;
      j++;
    }
    ans += min(a, b);
    i = j;
  }
  cout << ans << "\n";
  return 0;
}
