#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.length() == 1) {
    cout << "0";
    return (0);
  }
  int k;
  cin >> k;
  int res = 0;
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < k; i++) {
    string pr;
    cin >> pr;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == pr[0]) {
        cnt1++;
        continue;
      }
      if (s[i] == pr[1]) {
        cnt2++;
        continue;
      }
      res += min(cnt1, cnt2);
      cnt1 = 0;
      cnt2 = 0;
    }
  }
  res += min(cnt1, cnt2);
  cout << res;
  return (0);
}
