t1, t2 = input().split('-')
x = t1.split()
y = t2.split()
signs = ['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker', 'JOKER']
# 1、判断是否有对王
if (len(x) == 2 and 'joker' in x) or (len(y) == 2 and 'joker' in y):
print('joker JOKER')
# 2、判断是否有4张炸弹
elif len(x) == 4 and len(y) == 4:
if signs.index(x[0]) < signs.index(y[0]):
print(*y)
else:
print(*x)
elif len(x) == 4:
print(*x)
elif len(y) == 4:
print(*y)
# 3、判断长度,单张,对子,三个,顺子,不同牌型输出ERROR
elif len(x) != len(y):
print('ERROR')
# 4、都是直接比较第一张牌的大小
else:
if signs.index(x[0]) < signs.index(y[0]):
print(*y)
else:
print(*x)