//15ms
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String s=null;
while((s=bf.readLine())!=null){
char chars[]=s.toCharArray();
int nums=0;
int hashh[]=new int[60];
for(int i=0;i<chars.length;i++){
nums=chars[i]-'A';
if(chars[i]>='A'&&chars[i]<='Z')
hashh[nums]=hashh[nums]+1;
else if(chars[i]>='a'&&chars[i]<='z'){
nums=nums-32;
hashh[nums]=hashh[nums]+1;
}
}
String str=bf.readLine();
char aa[]=str.toCharArray();
int ccc=0;
if(aa[0]>='A'&&aa[0]<='Z')
ccc=aa[0]-'A';
else
ccc=aa[0]-'a';
System.out.println(hashh[ccc]);
}
}
}