#include <bits/stdc++.h>
using namespace std;
const bool OJ = true;
const long long inf = 1LL << 60;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (long long i = 0; i < (((long long)((v).size()))); i++) os << v[i] << " ";
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (long long i = 0; i < (((long long)((v).size()))); i++) is >> v[i];
  return is;
}
template <class A, class B>
istream& operator>>(istream& is, tuple<A, B>& p) {
  is >> get<0>(p) >> get<1>(p);
  return is;
}
long long dp[100005][30];
string s;
long long k;
vector<tuple<char, char>> f;
bool ok(char x, char y) {
  return !binary_search((f).begin(), (f).end(), make_tuple(x, y));
}
long long solve(long long i, char prev) {
  if (i == ((long long)((s).size()))) return 0;
  long long& d = dp[i][prev - 26];
  if (d != -1) return d;
  long long ans = inf;
  if (ok(prev, s[i])) {
    ans = min(ans, solve(i + 1, s[i]));
  }
  ans = min(ans, 1 + solve(i + 1, prev));
  return d = ans;
}
void run() {
  cin >> s;
  cin >> k;
  f = vector<tuple<char, char>>();
  for (long long i = 0; i < (k); i++) {
    string tmp;
    cin >> tmp;
    char x = tmp[0];
    char y = tmp[1];
    f.emplace_back(x, y);
    f.emplace_back(y, x);
  }
  sort((f).begin(), (f).end());
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 'a' + 28) << endl;
}
int main(int argc, char* argv[]) {
  run();
  return 0;
}
