#include<iostream>
#include<string>
using namespace std;
int main()
{
string S;
string L;
while(cin >> S >> L)
{
int i = 0;
int j = 0;
while(i < S.size() && j < L.size())
{
if(S[i] == L[j])
{
i++;
}
j++;
}
if(i == S.size())
{
cout << j - 1 << endl;
}
else
{
cout << -1 << endl;
}
}
return 0;
}