#include #define SZ(x) ((int) (x).size()) using namespace std; typedef long long int64; int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); vector code(26); for(int i = 0; i < 26; ++i) { char ch; cin >> ch; cin >> code[ch - 'a']; } int n; cin >> n; map frequency; for(int i = 0; i < n; ++i) { string my_str; cin >> my_str; string encoded; for(const char& ch: my_str) { encoded += code[ch - 'a']; } frequency[encoded]++; } int best = 1; for(const auto& x: frequency) { if(x.second > best) best = x.second; } if(best == 1) { best = -1; } cout << best << '\n'; return 0; }