#include<stdio.h>
#include<string.h>
struct word
{
    char str[100];
    char ch;
};
int count0currences(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 = count0currence(w);
    printf("%d", result);
    return 0;
}