#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int dp[100010][26];
bool mark[30][30];
bool Conflict(char a, char b) {
  if (mark[a - 'a'][b - 'a']) return 1;
  return 0;
}
int main() {
  char str[100010];
  while (cin >> str) {
    memset(mark, 0, sizeof(mark));
    int n;
    char st[5];
    cin >> n;
    while (n--) {
      cin >> st;
      mark[st[0] - 'a'][st[1] - 'a'] = mark[st[1] - 'a'][st[0] - 'a'] = 1;
    }
    int len = strlen(str);
    for (int i = 0; i < 26; i++) dp[0][i] = INF;
    dp[0][str[0] - 'a'] = 0;
    for (int i = 1; i < len; i++) {
      int k = str[i] - 'a';
      for (int j = 0; j < 26; j++) {
        if (j != k) dp[i][j] = dp[i - 1][j] + 1;
      }
      dp[i][k] = min(dp[i - 1][k], i);
      for (int j = 0; j < 26; j++) {
        if (Conflict('a' + j, str[i]) == 0)
          dp[i][k] = min(dp[i][k], dp[i - 1][j]);
      }
    }
    int Max = INF;
    for (int i = 0; i < 26; i++) {
      Max = min(Max, dp[len - 1][i]);
    }
    cout << Max << endl;
  }
  return 0;
}
