#include<stdio.h>
#include<string.h>
struct wrddata{
    char word[101];
    char letter;
};
int countocc(struct wrddata 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 wrddata d;
    scanf("%s",d.word);
    scanf(" %c",&data.letter);
    int result = countocc(d);
    if(result==0)
    {
        printf("-1");
    }
    else
    {
        printf("%d",result);
    }
    return 0;
}