def check(p):
p = p.split()
if len(p) == 2 and sorted(p) == sorted(['joker','JOKER']) : return 0
elif len(p) == 2 and len(set(p)) == 1 : return 2
elif len(p) == 3 and len(set(p)) == 1 : return 3
elif len(p) == 4 and len(set(p)) == 1 : return 4
elif len(p) == 1 : return 1
else: return 5
# elif len(p) == 5 and len(set(p)) == 5 and max(p)-min(p) == 4 : return 5
# else : return -1
def compar_pai(a,b):
pp1 , pp2 = a.split()[0],b.split()[0]
# print( pp1 , pp2)
if 'JOKER' in [pp1,pp2] : print('JOKER')
elif 'joker' in [pp1,pp2] : print('joker')
elif 'A' in [pp1,pp2] : print(a if 'A' in a else b)
elif 'K' in [pp1,pp2] : print(a if 'K' in a else b)
elif 'Q' in [pp1,pp2] : print(a if 'Q' in a else b)
elif 'J' in [pp1,pp2] : print(a if 'J' in a else b)
elif '10' in [pp1,pp2] : print(a if '10' in a else b)
else : print(a if pp1>pp2 else b)
p1 , p2 = input().split('-')
check1, check2 = check(p1), check(p2)
# print(check1, check2)
if (check1 == 0 or check2 == 0) and check1 != check2: print('joker','JOKER')
elif check1 == 4 and check2 != 4 : print(p1)
elif check1 != 4 and check2 == 4 : print(p2)
elif check1 == check2: compar_pai(p1,p2)
else : print('ERROR')