N=input() if len(N)<3: print(int(N)//3-3) else: m=0 n=0 for c in N: d,r=divmod(int(c),3) n=n*4+max(m,d) if r>0: m=3 print(n+15)