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