n = int(input()) assert 1 <= n <= 10 ** 15 ans = 0 for v in range(1, 100001): if int(str(v) * 3) <= n: ans += 1 print(ans)