three = set() for i in range(1, 100000): s = str(i) three.add(int(s + s + s)) n = int(input()) print(len([t for t in three if t <= n]))