#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
int32_t main() {
  string s;
  cin >> s;
  int n = s.length();
  int k;
  cin >> k;
  int count = 0;
  unordered_set<string> pair;
  for (int i = 0; i < k; i++) {
    string p;
    cin >> p;
    pair.insert(p);
    reverse(p.begin(), p.end());
    pair.insert(p);
  }
  for (int i = 0; i < n - 1;) {
    string key(1, s[i]);
    key += s[i + 1];
    if (pair.find(key) == pair.end()) {
      i++;
      continue;
    }
    int start = i;
    int index = i;
    int c1 = 0, c2 = 0;
    while (index < n && (s[index] == s[start] || s[index] == s[start + 1])) {
      if (s[index] == s[start]) c1++;
      if (s[index] == s[start + 1]) c2++;
      index++;
    }
    i = index;
    index = start - 1;
    while (index >= 0 && (s[index] == s[start] || s[index] == s[start + 1])) {
      if (s[index] == s[start]) c1++;
      if (s[index] == s[start + 1]) c2++;
      index--;
    }
    count += min(c1, c2);
  }
  cout << count << endl;
  return 0;
}
