#C - 755 解2
Set753 = {7, 5, 3}

num = int(input())
count = 0
for i in range(357, num+1):
    nSet = set([])
    n = i
    while n>0:
        d = n%10
        if d in Set753:
            nSet.add(d)
            n //= 10
        else: 
            nSet = set([])
            break
    if nSet=={}: continue 
    elif nSet==Set753: 
        #print(i,end=', ') #
        count += 1
print(count) 