N = int(input()) if N < 100: ans = N//3-3 else: S = str(N) c1 = 0 c2 = 0 f = True for i in range(len(S)): if i == 0: c1 = (int(S[i])-1)//3+1 else: c1 = c1*4+c2*((int(S[i])+2)//3) if int(S[i])%3 == 0 and f: c2 = 1 else: f = False c2 = 0 ans = c1+c2+14 print(ans)