#yuki1849 n=int(input()) res=0 for i in range(1,10**6): if int(str(i)*3)<=n: res+=1 print(res)