import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String[] str1,str2;
String[] tmp = str.split("-");
if (tmp.length < 2) {
System.out.println("ERROR");
return;
}
str1 = tmp[0].split(" ");
str2 = tmp[1].split(" ");
HashMap<String, Integer> map = new HashMap<>();
map.put("3", 3);
map.put("4", 4);
map.put("5", 5);
map.put("6", 6);
map.put("7", 7);
map.put("8", 8);
map.put("9", 9);
map.put("10", 10);
map.put("J", 11);
map.put("Q", 12);
map.put("K", 13);
map.put("A", 14);
map.put("2", 15);
map.put("joker", 16);
map.put("JOKER", 17);
if ( isJokerBomb(str1)||isJokerBomb(str2) ) {
System.out.println("joker JOKER");
}else if( isBomb(str1) && !isBomb(str2) ){
System.out.println(tmp[0]);
}else if( !isBomb(str1) && isBomb(str2) ) {
System.out.println(tmp[1]);
}else if ( str1.length == str2.length ) {
if (map.containsKey(str1[0]) && map.containsKey(str2[0])){
System.out.println( map.get(str1[0]) > map.get(str2[0]) ? tmp[0]:tmp[1] );
}
}else {
System.out.println("ERROR");
}
}
static boolean isBomb(String[] str){
return str.length == 4;
}
static boolean isJokerBomb(String[] str){
return str.length == 2 && (str[0].equals("joker") && str[1].equals("JOKER")) || (str[1].equals("joker") && str[0].equals("JOKER"));
}
}
#笔试题目#