#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
int n=0,a,b,i,j,c=0;
string word,sentence;
cin>>word;
cin>>sentence;
b=word.length();
a=sentence.length();
for(i=0;i<a;i++){
if(sentence[i]==' '){
j=0;
c=0;
}else{
for(j=0;j<b;j++){
if(word[j]==sentence[i]||word[j]+32==sentence[i]||word[j]-32==sentence[i]){
c++;
}else{
j=0;
c=0;
}
if(j==b-1&&c==b){
n++;
}
}
}
}
if(n==0){
cout<<-1;
}else{
cout<<n<<endl;
}
return 0;
}