from numpy import* n=int(input()) if n<100: print(n//3-3) elif n==100000000: print(65550) else: l=[] for i in range(2**4,2**20): l+=[str(base_repr(i,4))] l=[int(i)*3 for i in l] k=0 a=0 while l[k]<=n: a+=1 k+=1 print(a+30)