while True:
try:
card_dict = {
'1': 1,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
'10': 10,
'J': 11,
'Q': 12,
'K': 13,
'A': 14,
'2': 15,
'joker': 16,
'JOKER': 17
}
first_card, second_card = input().split('-')
first_num = len(first_card.split())
second_num = len(second_card.split())
if 'JOKER' in first_card:
print(first_card)
elif 'JOKER' in second_card:
print(second_card)
elif first_num != second_num and first_num != 4 and second_num != 4:
print('ERROR')
elif first_num != second_num:
if first_num == 4:
print(first_card)
elif second_num == 4:
print(second_card)
elif first_num == second_num:
if card_dict[first_card.split()[0]] > card_dict[second_card.split()[0]]:
print(first_card)
else:
print(second_card)
except:
break