#include <bits/stdc++.h>
using namespace std;
string S;
int k;
bool fb[26][26];
int dp[100000][26];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> S >> k;
  for (int i = 0; i < k; ++i) {
    string s;
    cin >> s;
    fb[s[0] - 'a'][s[1] - 'a'] = fb[s[1] - 'a'][s[0] - 'a'] = 1;
  }
  for (char c = 'a'; c <= 'z'; ++c) dp[0][c - 'a'] = (S[0] == c ? 0 : 1);
  for (int i = 1; i < S.size(); ++i) {
    for (int j = 0; j < 26; ++j) dp[i][j] = dp[i - 1][j] + 1;
    dp[i][S[i] - 'a'] = i;
    for (char c = 'a'; c <= 'z'; ++c)
      if (!fb[c - 'a'][S[i] - 'a'])
        dp[i][S[i] - 'a'] = min(dp[i][S[i] - 'a'], dp[i - 1][c - 'a']);
  }
  int res = 1000000000;
  for (char c = 'a'; c <= 'z'; ++c) res = min(res, dp[S.size() - 1][c - 'a']);
  cout << res << endl;
  return 0;
}
