import itertools def main(): N = int(input()) for i in itertools.count(1): if int(str(i)*3) > N: print(i-1) break if __name__ == '__main__': main()