def main(): N = int(input()) ans = 0 for i in range(1, 1050000): mozi = str(i) * 3 if int(mozi) <= N: ans += 1 print(ans) if __name__ == '__main__': main()