import sys
lst=input().split('-')
pk_1=lst[0].split()
pk_2=lst[1].split()
pk_1_str=' '.join(pk_1)
pk_2_str=' '.join(pk_2)
num_1=len(pk_1)
num_2=len(pk_2)
dic = {'3' : 1, '4' : 2, '5' : 3, '6' : 4, '7' : 5, '8': 6,'9': 7, '10' : 8, 'J' : 9, 'Q' : 10, 'K' : 11, 'A' : 12,'2' : 13, 'joker' : 14, 'JOKER' : 15}
if num_1==num_2:
a=pk_1[0]
b=pk_2[0]
if dic[a] > dic[b]:
print(pk_1_str)
else:
print(pk_2_str)
else:
if 'joker JOKER' in pk_1_str or 'joker JOKER' in pk_2_str:
print('joker JOKER')
elif num_1==4 and len(set(pk_1)) == 1:
print(pk_1_str)
elif num_2==4 and len(set(pk_2)) == 1:
print(pk_2_str)
else:
print('ERROR')