hand= list(map(lambda x: list(x) if len(x) == 2 else ["10", x[-1]], input().split()))

YES = True
NO = False

YOU_WON = NO

values = {
    "2": 2,
    "3": 3,
    "4": 4,
    "5": 5,
    "6": 6,
    "7": 7,
    "8": 8,
    "9": 9,
    "10": 10,
    "J": 10,
    "Q": 10,
    "K": 10,
    "A": 10,
}

value = 0
for card in hand:
    value += values[card[0]]

hist = []

def rep(f, l):
    return list(filter(f, l))

def f1():
    global value
    global hand
    old_val = value

    if len(hand) >= 4:
        value += 1
        value += values[hand[0][0]] * len(rep(lambda x: x[0]=="J", hand))

        if old_val != value:
            hist.append(f1)

def f2():
    global value
    global hand
    old_val = value

    for suit in "DHCS":
        if len(rep(lambda x: x[1]==suit, hand)) >= 2:
            value *= 2

            if old_val != value:
                hist.append(f2)
            return

def f3():
    global value
    global hand
    old_val = value

    if all([len(rep(lambda x: x[1]==suit, hand))>0 for suit in "DHCS"]):
        value *= 2

        if old_val != value:
            hist.append(f3)

def f4():
    global value
    global hand
    old_val = value

    if True:
        value += abs(len(rep(lambda x: (x[1] in "CS"), hand)) - len(rep(lambda x: x[1] in "HD", hand)))

        if old_val != value:
            hist.append(f4)

def f5():
    global value
    global hand
    old_val = value

    if value%2 == 0:
        old = value
        for i in range(1, value+10):
            if old%i == 0:
                value += i
        if old_val != value:
            hist.append(f5)

def f6():
    global value
    global hand
    old_val = value

    if len(rep(lambda x: x[0]=="7", hand)) == 4:
        value -= 11**2

        if old_val != value:
            hist.append(f6)

def f7():
    global value
    global hand
    old_val = value

    if value >= 0:
        value += min(list(map(lambda x: values[x[0]], hand)))

        if old_val != value:
            hist.append(f7)

def f8():
    global value
    global hand
    old_val = value

    if value < 0:
        value *= -1

        if old_val != value:
            hist.append(f8)

def f9():
    global value
    global hand
    old_val = value

    pairs = {
        "2": "5",
        "5": "2",
        "6": "9",
        "9": "6",
    }
    
    if len(rep(lambda x: x[1]=="D", hand)) >= 3:
        value += 1
        hand = list(map(lambda x: [pairs[x[0]], x[1]] if x[0] in pairs else x, hand))

        if old_val != value:
            hist.append(f9)

def f10():
    global value
    global hand
    old_val = value

    order = list("23456789") + ["10"] + list("JQKA")
    sorted_hand = sorted(list(map(lambda x: order.index(x[0]), hand)))
    for i in range(1, len(sorted_hand)):
        if sorted_hand[i] != sorted_hand[i-1]+1:
            break
    else:
        value += len(rep(lambda x: x[0] == "A", hand))*5
        
        if old_val != value:
            hist.append(f10)

def f11():
    global value
    global hand
    old_val = value

    if len(hist) > 8:
        value += bin(value).count("1")

        if old_val != value:
            hist.append(f11)

def f12():
    global value
    global hand
    old_val = value

    if len(rep(lambda x: x[0]=="2", hand)) > 0:
        hist[-1]()

        if old_val != value:
            hist.append(f12)
        
def f13():
    global value
    global hand
    old_val = value

    if len(rep(lambda x: x[0]=="2", hand)) > 0:
        value *= 2

        if old_val != value:
            hist.append(f13)

def f14():
    global value
    global hand
    global YOU_WON
    global YES
    global NO
    old_val = value

    if value == 674:
        YOU_WON = YES

        if old_val != value:
            hist.append(f14)
    else:
        YOU_WON = NO

    return YOU_WON


#print("-> ", value)
for f in [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14]:
    f()
#    print(value, hand)

print(value)


    


