#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const double EPS = 1e-9;
int ar[] = {1, -1, 0, 0, 1, 1, -1, -1};
int ac[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n;
string s;
int a[30][30];
int dp[200005][30];
int solve(int i, int last) {
  if (i >= n) return 0;
  int &ret = dp[i][last];
  if (ret + 1) return ret;
  int sol1 = 1e9, sol2 = 1e9;
  sol1 = 1 + solve(i + 1, last);
  if (!a[last][s[i] - 'a']) sol2 = solve(i + 1, s[i] - 'a');
  return ret = min(sol1, sol2);
}
int main() {
  ios_base::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  cin >> s;
  n = s.size();
  int k;
  cin >> k;
  while (k--) {
    string s;
    cin >> s;
    a[s[0] - 'a'][s[1] - 'a'] = a[s[1] - 'a'][s[0] - 'a'] = true;
  }
  cout << solve(0, 26) << "\n";
  return 0;
}
