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