#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string s1,s2,s3;
char c;
while(cin>>c,c!=',') s1+=c;
while(cin>>c,c!=',') s2+=c;
while(cin>>c) s3+=c;
int a,b;
a=s1.find(s2);
b=s1.rfind(s3);
if(int(b-a-s2.size())<0||a<0||b<0) cout<<"-1";
else cout<<b-a-s2.size();
//cout<<b<<' '<<a<<' '<<s2.size();
}