N=int(raw_input())

sum = 0
#flag = 0
sample = set(['7', '5', '3'])

for i in range(3,N+1,10):
#    flag = 0
#    print str(i)

    nums = set(list(str(i)))

    if sample.issubset(nums) and len(nums.difference(sample)) == 0:
#        print i
        sum += 1
for i in range(5,N+1,10):
#    flag = 0
#    print str(i)

    nums = set(list(str(i)))

    if sample.issubset(nums) and len(nums.difference(sample)) == 0:
#        print i
        sum += 1
for i in range(7,N+1,10):
#    flag = 0
#    print str(i)

    nums = set(list(str(i)))

    if sample.issubset(nums) and len(nums.difference(sample)) == 0:
#        print i
        sum += 1


print sum
