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