n=int(input())
ans=0
list=["357","375","537","573","735","753"]
for i in range(0,50000):
	x=list[i]+"3"
	list.append(x)
	y=list[i]+"5"
	list.append(y)
	z=list[i]+"7"
	list.append(z)
    
	a="3"+list[i]
	list.append(a)
	b="5"+list[i]
	list.append(b)
	c="7"+list[i]
	list.append(c)


list_i=[int(s) for s in list]
list_i.sort()

for i in range(0,50000):
	if n>=list_i[i]:
		ans+=1
      
print(ans)