N = int(input()) ans = 0 for i in range(1, N + 1): if int(str(i) * 3) <= N: ans += 1 else: break print(ans)