#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
const int INF = (int)1e9;
const int MOD = 1e9 + 7;
inline int toInt(char c) { return c - 'a'; }
int n, dp[MAXN][27];
bool forbidden[27][27];
string s, a;
int rec(int idx, int prev) {
  if (idx == s.size()) return 0;
  int &ans = dp[idx][prev];
  if (ans != -1) return ans;
  ans = INF;
  int cur = toInt(s[idx]);
  if (forbidden[prev][cur])
    ans = min(ans, 1 + rec(idx + 1, prev));
  else {
    ans = min(ans, 1 + rec(idx + 1, prev));
    ans = min(ans, rec(idx + 1, cur));
  }
  return ans;
}
int main() {
  cin >> s;
  cin >> n;
  memset(forbidden, false, sizeof(forbidden));
  for (int i = 0; i < n; i++) {
    cin >> a;
    forbidden[toInt(a[0])][toInt(a[1])] = true;
    forbidden[toInt(a[1])][toInt(a[0])] = true;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 26) << endl;
  return 0;
}
