# https://yukicoder.me/problems/no/1185 from decimal import Decimal from itertools import combinations N = Decimal(input().strip()) count = 0 i = 12 while i <= N: if i % 3 != 0: i += 1 continue l = list(combinations(str(i), 2)) tf = True for j in l: if sum(list(map(int, j))) % 3 != 0: tf = False if tf: count += 1 i += 1 print(count)