#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 2;
const long long MAXINT = 1e18;
const int INF = 1e9;
int t, n, caseno = 0, a, b, c, d, u, v, w, flag = 0, k, p, h, ans = 0;
string s;
map<pair<int, int>, int> m;
int dp[MAX][27];
int solve(int pos, int last) {
  if (pos == s.size()) return 0;
  int &ret = dp[pos][last];
  if (ret != -1) return ret;
  ret = solve(pos + 1, last);
  if (m.find(make_pair(s[pos] - 'a', last)) == m.end())
    ret = max(ret, 1 + solve(pos + 1, s[pos] - 'a'));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string tmp;
    cin >> tmp;
    m[make_pair(tmp[0] - 'a', tmp[1] - 'a')] =
        m[make_pair(tmp[1] - 'a', tmp[0] - 'a')] = 1;
  }
  memset(dp, -1, sizeof(dp));
  cout << s.size() - solve(0, 26);
  return 0;
}
