#include <stdio.h>
#include <string.h>

struct wordData {
    char str[105];
    char ch;
};
int countOccurrence(struct wordData w) {
    int count = 0; w.str[i] != '\0'; i++)
    {
        if (w.str[i] == w.ch) {
            count++;
        }
    }
    return 0;
}
int main() {
    struct wordData w;
    
    scanf("%s", w.str);
    
    scanf(" %c", &w.ch);
    int result = countOccurrence(w);
    
    if (result == 0)
    prinf("-1");
    else
       printf("%d", result);
       return 0;
}