n=int(input()) c=0 for i in range(1,10): for j in range(1,10): c+=int(str(i)*j+"0"*(9-j)+str(i)*j)*(10**9+1)<=n print(c)