#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int dp[100005][30] = {0};   int A[40][40] = {0};   int main() {     string s, b;     cin >> s;     int k;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> b;       int x, y;       x = b[0] -  a ;       y = b[1] -  a ;       A[x][y] = A[y][x] = 1;     }     int n = s.length();     for (int i = 1; i <= n; i++)       for (int k = 0; k < 26; k++) {         dp[i][k] = dp[i - 1][k];         for (int j = 0; j < 26; j++)           if (!A[k][j] && s[i - 1] -  a  == k)             dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1);       }     int res = 0;     for (int i = 0; i < 26; i++) {       res = max(res, dp[n][i]);     }     cout << n - res;     return 0;   }   