// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 1e6 + 1;

int h[26];
int dp[16][N];
 
inline void solve() {
   string s;
   cin >> s;
   int n, ans(0);
   cin >> n;
   for (char i : s) {
       ++h[i-'a'];
   }
   rep(i,0,n-1) {
       cin >> s;
       for (char j : s) {
           ++dp[i][j-'a'];
       }
   }
   // rep(i,0,25) {
   //     cout << h[i] << ' ';
   // }
   // E;
   int x = 1<<n;
   for (int i = 0; i < x; ++i) {
       int temp[26] = {};
       int cnt (0);
       for (int j = 0; j < n; ++j) {
           if (i & (1<<j)) {
               for (int k = 0; k < 26; ++k) {
                   temp[k] += dp[j][k];
               }
               ++cnt;
           }
       }
       bool f = 1;
       for (int j = 0; j < 26; ++j) {
           if (temp[j] > h[j]) {
               f = 0;
               break;
           }
       }       
       if (f) {
           // cout << i << '\n';
           // rep(i,0,25) {
           //     cout << temp[i] << ' ';
           // }
           // E;
           ans = max(ans, cnt);
       }
   }
   cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}