n = int(input()) cnt = 0 for i in range(1, 100001): t = int(str(i) * 3) if t <= n: cnt += 1 print(cnt)