input = input() #열행
row = int(input[1])
column = (int(ord(input[0])) - int(ord('a'))) + 1
move = [(2, -1), (2, 1), (-2, 1), (-2, -1), (-1, 2), (-1, 2), (1, 2), (1, -2)] # (row, column)
result = 0
for m in move:
nr = row + m[0]
nc = column + m[1]
if nr < 1 or nr > 8 or nc < 1 or nc > 8:
continue
result += 1
print(result)