import sys
compare_str = "3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER"
while True:
    try:
        A, B = input().strip().split('-')
        #先判断大小王和炸这些特殊的 
        if A == "joker JOKER" or B == "joker JOKER":
            print("joker JOKER")
            continue
        if A.count(A[0]) == 4 and B.count(B[0]) != 4:
            print(A)
            continue
        if A.count(A[0]) != 4 and B.count(B[0]) == 4:
            print(B)
            continue
        #剩下的,需要牌的数量一样才能比较,不一样就输出"ERROR"
        if len(A.split()) != len(B.split()):
            print("ERROR")
            continue
        #只需要比较第一张牌,通过在compare_str的顺序比较
        if compare_str.find(A[0]) < compare_str.find(B[0]):
            print(B)
        else:
            print(A)

    except:
#         print(sys.exc_info())
        break