#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-10;
int n;
bool ng[30][30];
string str;
int memo[100010][30];
int calc(int pos, int a) {
  if (pos == n) return 0;
  if (memo[pos][a] != -1) return memo[pos][a];
  int &res = memo[pos][a] = 1 + calc(pos + 1, a);
  if (!ng[a][str[pos] - 'a']) res = min(res, calc(pos + 1, str[pos] - 'a'));
  return res;
}
int main() {
  int k;
  memset(ng, false, sizeof(ng));
  memset(memo, -1, sizeof(memo));
  cin >> str;
  n = str.size();
  cin >> k;
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    ng[s[0] - 'a'][s[1] - 'a'] = ng[s[1] - 'a'][s[0] - 'a'] = true;
  }
  cout << calc(0, 28) << endl;
  return 0;
}
