#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e5 + 9;
int n, dp[MAX_N][30];
bool vis[40][40];
string s;
int solve(int idx, int lst) {
  if (idx == n) return 0;
  int &ret = dp[idx][lst];
  if (~ret) return ret;
  ret = INT_MAX;
  if (!vis[min(lst, s[idx] - 'a')][max(lst, s[idx] - 'a')])
    ret = solve(idx + 1, s[idx] - 'a');
  ret = min(ret, solve(idx + 1, lst) + 1);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(dp, -1, sizeof(dp));
  int m;
  cin >> s >> m;
  n = s.size();
  char x, y;
  while (m--) {
    cin >> x >> y;
    vis[min(x, y) - 'a'][max(x, y) - 'a'] = 1;
  }
  cout << solve(0, 28);
}
