贪心
#include<iostream>
#include<vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> a, b;
bool cmp(string aa, string bb){
return find(b.begin(), b.end(), aa) > find(b.begin(), b.end(), bb);
}
int main()
{
int n, m;
while(cin >> n){
a = {}; b = {};
while(n--){
string tmp;
cin >> tmp; a.push_back(tmp);
}
cin >> m;
while(m--){
string tmp;
cin >> tmp; b.push_back(tmp);
}
int cnt = 0;
while(b.size() > 0){
sort(a.begin(), a.end(), cmp);
if(a[0] == b[0]){
cnt = -1;
break;
}
b.erase(b.begin(), find(b.begin(), b.end(), a[0]));
if(b.size() > 0) cnt ++;
}
cout << cnt << endl;
}
return 0;
}