n=input() if len(n) < 3: print(0) exit() if len(n)%3 != 0: print('9'*(len(n)//3)) exit() n=n[:len(n)//3] for i in range(1,10**5 + 1): if i > int(n): break ans = i print(ans)