#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int main() {
  string str;
  cin >> str;
  int k;
  int ans[30];
  memset(ans, 0, sizeof(ans));
  cin >> k;
  bool data[30][30];
  memset(data, false, sizeof(data));
  for (int i = 0; i < k; i++) {
    string tmp;
    cin >> tmp;
    int a = tmp[0] - 'a';
    int b = tmp[1] - 'a';
    data[a][b] = true;
    data[b][a] = true;
  }
  int size = str.size();
  ans[str[0] - 'a'] = 1;
  int sol = 1;
  for (int i = 1; i < size; i++) {
    int cur = str[i] - 'a';
    int next = 1;
    for (int j = 'a' - 'a'; j <= 'z' - 'a'; j++) {
      if (!data[cur][j]) {
        next = max(next, ans[j] + 1);
      }
    }
    ans[cur] = next;
    sol = max(sol, next);
  }
  int finalans = str.size() - sol;
  cout << finalans << endl;
  return 0;
}
