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