N = int(input()) ans = 0 for i in range(1,10**5+1): A = str(i) * 3 if N >= int(A): ans += 1 print(ans)