#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void RD(char *s) { scanf("%s", s); }
void RD(char &s) { scanf("%c", &s); }
void RD(string &s) { cin >> s; }
void PR(int x) { printf("%d\n", x); }
void PR(int x, int y) { printf("%d %d\n", x, y); }
void PR(long long x) { printf("%I64d\n", x); }
void PR(char x) { printf("%c\n", x); }
void PR(char *x) { printf("%s\n", x); }
void PR(string x) { cout << x << endl; }
const long long inf = 1;
const long long mod = 1LL;
map<pair<int, int>, bool> mp;
string s;
int dp[100010][27], N;
int solve(int pos, int last) {
  int &ret = dp[pos][last];
  if (~ret) return ret;
  if (pos == N) return 0;
  ret = solve(pos + 1, last);
  if (mp.find(make_pair(last, s[pos] - 'a')) == mp.end())
    ret = max(ret, 1 + solve(pos + 1, s[pos] - 'a'));
  return ret;
}
int main() {
  while (cin >> s) {
    (mp.clear());
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      string t;
      cin >> t;
      mp[make_pair(t[0] - 'a', t[1] - 'a')] =
          mp[make_pair(t[1] - 'a', t[0] - 'a')] = 1;
    }
    memset(dp, -1, sizeof(dp));
    N = (int)s.size();
    cout << (int)s.size() - solve(0, 26) << endl;
  }
  return 0;
}
