#include <bits/stdc++.h>
using namespace std;
const int N =2e5+10;
map<string,int> mp;
int f[N];
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr), cin.tie(nullptr);
string tp;
string s;
int res =0;
f[0] =1;
while(cin>>tp){
if(tp==".") break;
mp[tp] =1;
}
while(cin>>tp){
s +=tp;
}
s =" "+s;
int len = s.size()-1;
for(int i=0;i<=len;i++){
if(!f[i]) continue;
int maxj = min(i+10,len);
for(int j=1;j<=maxj;j++){
string str1 = s.substr(i+1,j);
if(mp[str1] ==1){
f[i+j] = 1;
res = max(res,i+j);
}
//cout<<str1<<endl;
}
}
cout<<res;
return 0;
}