import copy

#n=int(input())
#s=str(n)
ssst=str(input())
b = int(copy.copy(ssst))
#lit = list(map(int,input().split()))
count=0
#mmm=int(max(lit))*n
#ans=mmm-int(sum(lit))
#print(ans)
#arr=[]
#arr=s.rsplit("3","5","7")

th=0
fi=0
se=0

for i in range(100,b+1):
    #print(i,"i")
    m=str(i)
    for x in range(len(m)):

        for j in range(10):
            if j==int(m[x]) and j==3:
                th=th+1
            if j==int(m[x]) and j==5:
                fi=fi+1
            if j==int(m[x]) and j==7:
                se=se+1
    if len(m)==(th+fi+se) and th!=0 and fi!=0 and se!=0:
        count=count+1
        #print(count,"  ",i ," ",x)
    th=0
    fi=0
    se=0
print(count)
