#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, x;
  int k = 0, sum = 0;
  cin >> s;
  cin >> k;
  map<char, char> m;
  for (int i = 0; i < k; ++i) {
    cin >> x;
    m[x[0]] = x[1];
    m[x[1]] = x[0];
  }
  for (int i = 0; i < s.length(); ++i) {
    vector<int> freq(26, 0);
    while (i + 1 < s.length() &&
           ((s[i] == s[i + 1]) || (s[i + 1] == m[s[i]]))) {
      ++freq[s[i] - 'a'];
      ++i;
    }
    ++freq[s[i] - 'a'];
    int mx = 0;
    for (auto j : freq) mx = max(mx, j);
    sum += mx;
  }
  cout << s.length() - sum;
}
