#include <bits/stdc++.h>
using namespace std;
int forbid[256][256];
int memd[100005][256];
int bak[100005][256];
string ori;
int solve(int cur, char last) {
  if (cur == ori.size()) return 0;
  if (memd[cur][last]) return bak[cur][last];
  memd[cur][last] = 1;
  int& res = bak[cur][last];
  res = solve(cur + 1, last) + 1;
  if (!forbid[last][ori[cur]]) res = min(res, solve(cur + 1, ori[cur]));
  return res;
}
int main() {
  cin >> ori;
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    string t;
    cin >> t;
    forbid[t[1]][t[0]] = forbid[t[0]][t[1]] = 1;
  }
  cout << solve(0, ' ');
  return 0;
}
