A=[6,2,5,5,4,5,6,3,7,6] for i in range(10,10**5+1): x=i tmp=0 while 1: one=x%10 tmp+=A[one] rest=x//10 x=rest if x==0:break A.append(tmp) #print(A) N=int(input()) idx=0 for x in range(10**5+1): if N>=A[x]:idx=x print(idx)