#include <bits/stdc++.h>
using namespace std;
int n, mem[100004][28];
char x, y;
string s;
map<pair<int, int>, int> m;
int dp(int i = 0, int j = 27) {
  if (i == (int)s.size()) return 0;
  int& ret = mem[i][j];
  if (~ret) return ret;
  if (m[{(int)(s[i] - 'a'), j}] != 1) {
    return ret = max(dp(i + 1, (int)(s[i] - 'a')) + 1, dp(i + 1, j));
  } else
    return ret = dp(i + 1, j);
}
int main() {
  cin >> s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    m[{(int)(x - 'a'), (int)(y - 'a')}] = 1;
    m[{(int)(y - 'a'), (int)(x - 'a')}] = 1;
  }
  memset(mem, -1, sizeof mem);
  cout << (int)s.size() - dp();
  return 0;
}
