#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 2 * 100000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;
const int L = 27;
int C[L];
string s;
int k;
int dp[MAX][L];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> k;
  memset(C, -1, sizeof(C));
  for (int i = (0); i < (k); i++) {
    string s;
    cin >> s;
    int ch1 = s[0] - 'a';
    int ch2 = s[1] - 'a';
    C[ch1] = ch2;
    C[ch2] = ch1;
  }
  for (int i = (0); i < ((int)s.size() + 1); i++) {
    for (int j = (0); j < (L); j++) dp[i][j] = INF;
  }
  dp[0][L - 1] = 0;
  for (int i = (0); i < ((int)s.size()); i++) {
    int ch = s[i] - 'a';
    for (int j = (0); j < (L); j++) {
      if (dp[i][j] == INF) continue;
      if (C[j] != ch) {
        dp[i + 1][ch] = min(dp[i + 1][ch], dp[i][j]);
      }
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
    }
  }
  int ans = INF;
  for (int i = (0); i < (L); i++) ans = min(ans, dp[(int)s.size()][i]);
  cout << ans << endl;
}
