
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
public class Demo05 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = 0;
TreeSet<Integer> set1 = new TreeSet<>();
TreeSet<String> set2 = new TreeSet<>();
HashMap<Integer,Integer> map = new HashMap<>();
while(n < 5){
int p;
String s;
String pStr;
pStr = sc.next();
s = sc.next();
if(pStr.equals("J")){
p = 11;
}else if(pStr.equals("Q")){
p = 12;
}else if(pStr.equals("K")){
p = 13;
}else if(pStr.equals("A")){
p = 1;
}else{
p = Integer.parseInt(pStr);
}
set1.add(p);
set2.add(s);
if(null != map.get(p)){
map.put(p,map.get(p)+1);
}else{
map.put(p,1);
}
n++;
}
boolean isTongHua = false;
if(set2.size() == 1){
isTongHua = true;
}
int mostNum = 1;
for(Integer i:map.keySet()){
if(map.get(i) > mostNum) {
mostNum = map.get(i);
}
}
if(isTongHua && mostNum == 1){
if((set1.last() - set1.first()) == 4){
System.out.println(1);
return;
}else if(set1.contains(1) && set1.contains(10) && set1.contains(11) && set1.contains(12) && set1.contains(13)){
System.out.println(1);
return;
}
}
if(mostNum == 4){
System.out.println(2);
return;
}
if(mostNum == 3 && map.keySet().size() == 2){
System.out.println(3);
return;
}
if(isTongHua){
System.out.println(4);
return;
}
if(mostNum == 1) {
if ((set1.last() - set1.first()) == 4) {
System.out.println(5);
return;
} else if (set1.contains(1) && set1.contains(10) && set1.contains(11) && set1.contains(12) && set1.contains(13)) {
System.out.println(5);
return;
}
}
if(mostNum == 3 && map.keySet().size() == 3){
System.out.println(6);
return;
}
System.out.println(7);
return;
}
}