n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
    if sum(j)==3:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(10):
    tmp=[]
    for j in zenbu:
        tmp.append(j*10+3)
        tmp.append(j*10+5)
        tmp.append(j*10+7)
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)
      