n = int(input().strip()) ls = [ 1000000001, 11000000011, 111000000111, 1111000001111, 11111000011111, 111111000111111, 1111111001111111, 11111111011111111, 111111111111111111, ] total = 0 for a in ls: x = a for _ in range(9): if n > x: total += 1 x += a else: print(total) raise SystemExit print(total)