n = input() l = str(n) if len(l) == 1: a = 9 b = 10 - 1 print(a + b) else: a = 9 b = 9 * len(l) print(a + b)