#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
char s[MAXN];
int n, k;
vector<pair<char, char> > v;
int main() {
  scanf("%s%d", s, &k);
  n = strlen(s);
  for (int i = 0; i < k; ++i) {
    char r[3];
    scanf("%s", r);
    v.push_back(make_pair(r[0], r[1]));
  }
  int res = 0;
  int a = 0, b = 0;
  for (int i = 0; i < v.size(); ++i) {
    for (int j = 0; j < n; ++j) {
      if (s[j] != v[i].first && s[j] != v[i].second)
        res += min(a, b), a = b = 0;
      else if (v[i].first == s[j])
        ++a;
      else
        ++b;
    }
  }
  res += min(a, b);
  printf("%d", res);
}
