from itertools import product

N = int(eval(input()))

ans = 0

for l in range(1, 11):

    for p in product("357", repeat=l):

        v = "".join(p)

        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:

            ans += 1

print(ans)
N = int(eval(input()))



cnt = 0

def dfs(s):

    global cnt

    if '3' in s and '5' in s and '7' in s and int(s) <= N:

        cnt += 1

    if len(s) >= 10:

        return cnt

    dfs(s + '3')

    dfs(s + '5')

    dfs(s + '7')

    return cnt



print((dfs('')))
from itertools import product

N = int(eval(input()))
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
            ans += 1
print(ans)

N = int(eval(input()))
cnt = 0


def dfs(s):
    global cnt
    if "3" in s and "5" in s and "7" in s and int(s) <= N:
        cnt += 1
    if len(s) >= 10:
        return cnt
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")
    return cnt


print((dfs("")))

-from itertools import product +N = int(eval(input())) +cnt = 0 -N = int(eval(input())) -ans = 0 -for l in range(1, 11): -    for p in product("357", repeat=l): -        v = "".join(p) -        if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N: -            ans += 1 -print(ans) + +def dfs(s): +    global cnt +    if "3" in s and "5" in s and "7" in s and int(s) <= N: +        cnt += 1 +    if len(s) >= 10: +        return cnt +    dfs(s + "3") +    dfs(s + "5") +    dfs(s + "7") +    return cnt + + +print((dfs("")))