N=int(raw_input())

sum = 0
flag = 0

for i in range(1,N+1):
    flag = 0
#    print str(i)
    nums = set(list(str(i)))
    for n in ['7', '5', '3']:
        if n in nums:
            nums.remove(n)
        else:
            flag = 1
            break
    if len(nums) == 0 and flag ==0:
#        print '!!753num!!'
        sum += 1

print sum
