n = int(input())
ans = 0

for i in range(n + 1):
    if "3" in str(i) and \
            "5" in str(i) and \
            "7" in str(i) and \
            "1" not in str(i) and \
            "2" not in str(i) and \
            "4" not in str(i) and \
            "6" not in str(i) and \
            "8" not in str(i) and \
            "9" not in str(i) and \
            "0" not in str(i):
        ans += 1

print(ans)
