#include <bits/stdc++.h>
using namespace std;
const int INF = 100000001;
const double EPS = 10e-9;
int pp[26];
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < 26; ++i) pp[i] = 0;
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string v;
    cin >> v;
    pp[v[0] - 'a'] = -(i + 1);
    pp[v[1] - 'a'] = i + 1;
  }
  int ans = 0;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    int cl = pp[s[i] - 'a'];
    int cc = 1;
    int ac = 0;
    while (i + 1 < n) {
      ++i;
      if (pp[s[i] - 'a'] == cl) {
        ++cc;
      } else if (pp[s[i] - 'a'] == -cl) {
        ++ac;
      } else {
        --i;
        break;
      }
    }
    ans += max(ac, cc);
  }
  cout << n - ans << "\n";
}
