while True:
    try:
        a,b = input().split('-')
        la,lb = a.split(),b.split()
        d = {'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}
        if a == 'joker JOKER' or b == 'joker JOKER':
            print('joker JOKER')
        elif len(la) == 4 and len(lb) !=4:
            print(a)
        elif len(lb) == 4 and len(la) != 4:
            print(b)
        elif len(la) != len(lb):
            print('ERROR')
        else:
            print(a) if d[la[0]] > d[lb[0]] else print(b)
    except:
        break