n = int(input())

if n < 357:
    print("0")
    exit()

#print(list(str(n)))
answer = 0

sgs = set(['7', '5', '3'])

for i in range(357, n):
    s = list(str(i))
    if set(s) == sgs:
        answer += 1

print(answer)
