N=int(input())
r=filter
f=lambda c:sum([map(lambda z:z+y,f(c-1))for y in'357'],[]) if c!=0 else ['']
print(sum([len(r(lambda y:y==3,map(lambda x:len(set(sorted(x))),r(lambda z:int(z)<=N,f(e+1)))))for e in range(10)]))
