#include<bits/stdc++.h>
using namespace std;
const int L=26,N=200005;
string y;
int tot=1;
bool ch[N];
long long sum;
struct Tree{
int son[L];
bool f=0;
}t[N*5];
int Give(char w){
return (w-'A');
}
void update(int u,string z){
int id,len=z.length();
for(int i=0;i<len;i++){
id=Give(z[i]);
if(t[u].son[id]==0)t[u].son[id]=++tot;
u=t[u].son[id];
}
t[u].f=1;
}
long long query(int u,string z){
int len=z.length();
for(int i=0;i<len;i++){
if(ch[i]){
sum=i;
int p=0;
for(int j=i;j<len;j++){
int id=Give(z[j]);
if(t[p].son[id]==0)break;
if(t[p].f){
ch[j]=1;
}
p=t[p].son[id];
}
}
}
return sum;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string z;
while(cin>>z&&z!="."){
update(1,z);
}
while(cin>>z){
y+=z;
}
cout<<query(1,y);
return 0;
}