n = int(input())


def func(s):
    if int(s) > n:
        return 0
    count = 1 if all(s.count(l) for l in "357") else 0
    for l in "357":
        count += func(s+l)
    return count


print(func("0"))