def resolve(): nstr = input() length = len(nstr) n = int(nstr) if length == 2: print(n//3-3) return ten_i = [10**i for i in range(length)] import itertools result = 14 #100//3 - 4*4 -3 l=[] for pattern in itertools.product([0,3,6,9], repeat=length): x = sum([teni * ai for teni, ai in zip(ten_i,pattern)]) if x <= n: result += 1 l.append(x) print(result) resolve()