// editor1
#include<stdio.h>
#include<string.h>
struct WorldDate{
    char Word[101];
    char letter;
};
int count0ccurrence(struct WordDate w){
    int count =0;
    for(int i=0;i<strlen(w.word); i++)
    {
        if(w.word[i] ==w.letter){
            count++;
        }
    }
return count;
}
int main(){
    struct wordData data;
    scanf("%s",data.word);
    scanf("%c",&data.letter);
    int result = countoccurrence(data));
    if(result ==0)
    {
        printf("-1");
    }
    else{
        printf("%d",result);
    }