import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine().trim();
        Map<Character, Integer> map = new HashMap<>();
        for(int i = 0; i < str.length(); i++){
            char c = str.charAt(i);
            if(c >= 'a'&& c <= 'z'){
                if(map.containsKey(c)){
                    map.put(c, (map.get(c) + 1));
                }else{
                    map.put(c, 1);
                }
            }else if(c >= 'A' && c <= 'Z'){
                c =  Character.toLowerCase(c);
                if(map.containsKey(c)){
                    map.put(c, (map.get(c) + 1));
                }else{
                    map.put(c, 1);
                }               
            }else{
                continue;
            }
        }
        String charStr = br.readLine();
        char target = Character.toLowerCase(charStr.charAt(0));

        if(map.containsKey(target)){
            System.out.print(map.get(target));
        }else{
            System.out.println(0);
        }
    }
}