n=int(input()) if n<100: print(n//3-3) else: e=len(str(n))-1 s=[0,30,48,192,768,3072,12288,49152,196608,786432,3145728] m=0 for i in range(e): m+=s[i] l=[int(i)//3+1 for i in list(str(n).strip())] l[0]-=1 a=1 for i in l: a*=i print(m+a)