#include<stdio.h>
#include<string.h>
struct word{
    char str[100];
    char ch;
};
int count0ccurences(struct word w){
    int count=0;
    for(int i=0; i<strlen(w.str;)i++)
    {
        if(w.str[i]==w.ch)
        count++;
    }
    if(count==0)
    return -1;
    else
    return count;
}
int main()
{
    struct word w;
    scanf("%s",w.str);
    scanf" %c", &w.ch);
    int result=count0ccurences(w);
    printf("%d",result);
    return 0;
}