#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1E9;
const long long INFLL = (long long)11E15;
const long long MOD = (long long)1E9 + 7;
const double PI = acos(-1);
const double EPS = 1E-9;
bool between(int x, int l, int r) { return (l <= x && x <= r); }
string tostring(int x) {
  char dum[20];
  sprintf(dum, "%d", x);
  string ret(dum);
  return ret;
}
int DP[100010][35];
int A[35];
string S;
int n;
int f(int pos, int last) {
  if (pos == S.size()) return 0;
  int &ret = DP[pos][last];
  if (ret != -1) return ret;
  ret = f(pos + 1, last) + 1;
  if (A[last] != S[pos] - 'a') ret = min(ret, f(pos + 1, S[pos] - 'a'));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(A, -1, sizeof A);
  cin >> S >> n;
  for (int i = 0; i < n; i += 1) {
    string x;
    cin >> x;
    A[x[0] - 'a'] = x[1] - 'a';
    A[x[1] - 'a'] = x[0] - 'a';
  }
  memset(DP, -1, sizeof DP);
  cout << f(0, 30) << endl;
  return 0;
}
