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