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 if int(str(i)*3) <= int(N): ans = i print(ans)