#include <bits/stdc++.h>
using namespace std;
int main() {
  string txt = "";
  cin >> txt;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string p = "";
    cin >> p;
    for (int i = 0; i < txt.size(); i++) {
      int tmp = i;
      int cnt_f = 0, cnt_s = 0;
      while (txt[i] == p[0] || txt[i] == p[1]) {
        if (txt[i] == p[0]) {
          cnt_f++;
        } else {
          cnt_s++;
        }
        i++;
      }
      ans += min(cnt_f, cnt_s);
    }
  }
  cout << ans << endl;
  return 0;
}
