N = int(input()) ans = 0 for i in range(1,10**6): s = str(i) if int(s+s+s) <= N: ans += 1 print(ans)