def k(x):
    if x == 1:
        return 1
    else:
        return 2

def n(x):
    if x <= 2:
        return 1
    else:
        return 2

try:
    while 1:
        S, T = input().split()
        S = int(S)
        if T in "BR":
            print(S)
        elif T == "K":
            print(k(S))
        else:
            print(n(S))


except EOFError:
    pass
