# 1桁はない、2桁では3の倍数すべて12-99 # 3桁以上では、全桁が0369のどれか N = int(input()) import sys sys.setrecursionlimit(10**7) def dfs(num): if 100 <= num <= N: nums.append(num) if num*10+0 <= N: dfs(num*10+0) if num*10+3 <= N: dfs(num*10+3) if num*10+6 <= N: dfs(num*10+6) if num*10+9 <= N: dfs(num*10+9) nums = [] dfs(3) dfs(6) dfs(9) nums.sort() #print(nums) if N <= 100: ans = N//3 - 10//3 else: ans = 100//3-10//3 ans += len(nums) print(ans)