#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    v.push_back(t);
  }
  int ans = 0;
  if (s.length() == 1) {
    cout << 0 << endl;
    return 0;
  }
  s += "1";
  int arr[255] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == v[i][0] || s[j] == v[i][1]) {
        arr[s[j]]++;
      } else {
        ans += (min(arr[v[i][0]], arr[v[i][1]]));
        arr[v[i][0]] = 0;
        arr[v[i][1]] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
