#include<stdio.h>
#include<string.h>
struct word
{
    char n[50];
    char m;
    int c;
};
int main()
{
    struct word p;
    p.c=0;
    fgets(p.n,sizeof(p.n),stdin);
    scanf("%c",p.m);
    int u=strlen(p.n);
    for(int i=0;i<u;i++)
    {
        if(p.n[i]==p.m)
        {
            p.c++;
        }
    }
    if(p.c>0)
    {
        printf("%d",p.c);
    }
    else
    {
        printf("-1");
    }
}