from itertools import * N = int(input()) ans = 0 for i in range(10, min(100, N + 1)): s = str(i) a, b = int(s[0]), int(s[1]) if (a + b) % 3 == 0: ans += 1 for tup in product(["3", "6", "9", "0"], repeat=10): n = int("".join(tup)) if 100 < n <= N: ans += 1 print(ans)