## https://yukicoder.me/problems/no/1185 MOD = 998244353 def main(): N = int(input()) answer = 0 for n in range(10, min(99, N) + 1): if n % 3 == 0: answer += 1 # 3桁以上の自然数について for bit in range(4 ** 10): number = 0 for _ in range(10): number *= 10 b = bit % 4 number += 3 * b bit //= 4 if number % 3 == 0 and number <= N and number >= 100: answer += 1 print(answer) if __name__ == "__main__": main()