n = int(input()) ans = 0 i = 1 while 1: x = int(str(i) * 3) if x > n: break i += 1 print(i - 1)