n=int(input()) s=str(n) ans=0 for v in range(1,100001): if int(str(v)*3)<=n: ans+=1 print(ans)