#include <iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

int getCount(vector<string>& IP_proxy,vector<string>& IP_visit,int n2){
    int count=-1,index=0;
    while(index<n2){
        int maxn=-1;
        for(string s:IP_proxy){
            auto iter=find(IP_visit.begin()+index,IP_visit.end(),s);
            if(iter-IP_visit.begin()>maxn)
                maxn=iter-IP_visit.begin();
        }
        count++;
        index=maxn;
    }
    return count;
}

int main() {
    int n1, res;
    while (cin >> n1) { // 注意 while 处理多个 case
        res = 0;
        vector<string> IP_proxy(n1);
        for (int i = 0; i < n1; i++) {
            cin >> IP_proxy[i];
        }
        int n2;
        cin >> n2;
        vector<string> IP_visit(n2);
        for (int i = 0; i < n2; i++) {
            cin >> IP_visit[i];
        }
        if(n1==1&&find(IP_visit.begin(),IP_visit.end(),IP_proxy[0])!=IP_visit.end()){
            cout<<-1<<endl;
            continue;
        }
        else
            cout<<getCount(IP_proxy,IP_visit,n2);
    }
}
// 64 位输出请用 printf("%lld")