#include <bits/stdc++.h>
using namespace std;
string st;
long bad;
long ar[200][200];
long dp[105000][30];
long ans;
string st1;
long temp, answ;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> st;
  cin >> bad;
  for (; bad; --bad) {
    cin >> st1;
    ar[st1[0] - 'a'][st1[1] - 'a'] = 1;
    ar[st1[1] - 'a'][st1[0] - 'a'] = 1;
  }
  for (int i = 0; i <= st.size(); i++)
    for (int last = 0; last <= 26; last++) dp[i][last] = 1e9;
  for (int i = 0; i <= 26; i++) dp[0][i] = 0;
  for (int i = 0; i < st.size(); i++)
    for (int last = 0; last < 26; last++) {
      temp = st[i] - 'a';
      dp[i + 1][last] = min(dp[i + 1][last], dp[i][last] + 1);
      if (ar[last][temp] == 0)
        dp[i + 1][temp] = min(dp[i + 1][temp], dp[i][last]);
    }
  answ = 1e9;
  for (int i = 0; i <= 26; i++) answ = min(answ, dp[st.size()][i]);
  cout << answ << endl;
  cin.get();
  cin.get();
  return 0;
}
