# coding: utf-8 # Your code here! n = int(input()) cnt = 0 for i in range(10, min(100, n + 1)): cnt = cnt + 1 if (int(str(i)[0]) + int(str(i)[1])) % 3 == 0 and i % 3 == 0 else cnt if n > 100: numList = ['0', '3', '6', '9'] for a in range(4): for b in range(4): for c in range(4): for d in range(4): for e in range(4): for f in range(4): for g in range(4): for h in range(4): for i in range(4): s = int(numList[a] + numList[b] + numList[c] + numList[d] + numList[e] + numList[f] + numList[g] + numList[h] + numList[i]) if s <= n and s > 100: cnt += 1 print(cnt)