#include <bits/stdc++.h>
using namespace std;
int memo[100005][28], n, m;
vector<string> cad;
string s;
int DP(int pos, char last) {
  if (pos == m) return 0;
  if (memo[pos][last - 'a'] != -1) return memo[pos][last - 'a'];
  int ans1 = 0, ans2 = 0;
  bool yes = 0;
  for (int i = 0; i < n; i++) {
    if (s[pos] == cad[i][0] && last == cad[i][1]) yes = 1;
    if (s[pos] == cad[i][1] && last == cad[i][0]) yes = 1;
  }
  if (!yes) ans1 = 1 + DP(pos + 1, s[pos]);
  ans2 = DP(pos + 1, last);
  return memo[pos][last - 'a'] = max(ans1, ans2);
}
int main() {
  string aux;
  cin >> s;
  m = s.size();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    cad.push_back(aux);
  }
  memset(memo, -1, sizeof memo);
  int x = DP(0, char('z' + 1));
  printf("%d\n", m - x);
}
