#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, bool> mp;
string s;
int dp[100010][27], N;
int solve(int pos, int last) {
  int &ret = dp[pos][last];
  if (~ret) return ret;
  if (pos == N) return 0;
  ret = solve(pos + 1, last);
  if (mp.find(make_pair(last, s[pos] - 'a')) == mp.end())
    ret = max(ret, 1 + solve(pos + 1, s[pos] - 'a'));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> s) {
    (mp.clear());
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string t;
      cin >> t;
      mp[make_pair(t[0] - 'a', t[1] - 'a')] =
          mp[make_pair(t[1] - 'a', t[0] - 'a')] = 1;
    }
    memset(dp, -1, sizeof(dp));
    N = (int)s.size();
    cout << (int)s.size() - solve(0, 26) << endl;
  }
  return 0;
}
