import copy

ssst=str(input())
b = int(copy.copy(ssst))
th=fi=se=count=0

for i in range(100,b+1):
   
    m=str(i)
    if i%2!=1:
        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=fi=se=0
print(count)
