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