import math
count = 0
n = int(input())
# a = n%1000
# b = math.floor(n/1000)
# c=list(str(b))
# print(c)

for i in range(n):
    s = list(str(i))
    if '3' in s and '5' in s and '7' in s and not('0' in s or '1' in s or '2' in s or '4' in s or '6' in s or '8' in s or '9' in s):
        count += 1
print(count)
