from itertools import product



n = int(eval(input()))



res = 0

for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):

    p = int("".join(pattern))

    if "0" not in str(p):

        if p <= n:

            for i in ["3", "5", "7"]:

                if i not in str(p):

                    break

            else:

                res += 1

print(res)

n = int(eval(input()))





def dfs(s):

    if int(s) > n:

        return 0

    for i in '753':

        if s.count(i) == 0:

            res = 0

            break

    else:

        res = 1

    for i in '753':

        res += dfs(s + i)



    return res





print((dfs('0')))

from itertools import product

n = int(eval(input()))
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
    p = int("".join(pattern))
    if "0" not in str(p):
        if p <= n:
            for i in ["3", "5", "7"]:
                if i not in str(p):
                    break
            else:
                res += 1
print(res)

n = int(eval(input()))


def dfs(s):
    if int(s) > n:
        return 0
    for i in "753":
        if s.count(i) == 0:
            res = 0
            break
    else:
        res = 1
    for i in "753":
        res += dfs(s + i)
    return res


print((dfs("0")))

-from itertools import product +n = int(eval(input())) -n = int(eval(input())) -res = 0 -for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))): -    p = int("".join(pattern)) -    if "0" not in str(p): -        if p <= n: -            for i in ["3", "5", "7"]: -                if i not in str(p): -                    break -            else: -                res += 1 -print(res) + +def dfs(s): +    if int(s) > n: +        return 0 +    for i in "753": +        if s.count(i) == 0: +            res = 0 +            break +    else: +        res = 1 +    for i in "753": +        res += dfs(s + i) +    return res + + +print((dfs("0")))