N = int(eval(input()))

def dfs(s):

    if int(s) > N:

        return 0

    else:

        if '7' in s and '5' in s and '3' in s:

            ret = 1

        else:

            ret = 0

        for i in '357':

            ret += dfs(s + i)

        return ret

print((dfs("0")))
from itertools import product



N = int(eval(input()))

ans = 0

for j in range(3, len(str(N))+1):

    for i in product("357", repeat=j):

        x = "".join(i)

        if 357 <= int(x) <= N and len(set(x)) == 3:

            ans += 1

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


def dfs(s):
    if int(s) > N:
        return 0
    else:
        if "7" in s and "5" in s and "3" in s:
            ret = 1
        else:
            ret = 0
        for i in "357":
            ret += dfs(s + i)
        return ret


print((dfs("0")))

from itertools import product

N = int(eval(input()))
ans = 0
for j in range(3, len(str(N)) + 1):
    for i in product("357", repeat=j):
        x = "".join(i)
        if 357 <= int(x) <= N and len(set(x)) == 3:
            ans += 1
print(ans)

+from itertools import product + - - -def dfs(s): -    if int(s) > N: -        return 0 -    else: -        if "7" in s and "5" in s and "3" in s: -            ret = 1 -        else: -            ret = 0 -        for i in "357": -            ret += dfs(s + i) -        return ret - - -print((dfs("0"))) +ans = 0 +for j in range(3, len(str(N)) + 1): +    for i in product("357", repeat=j): +        x = "".join(i) +        if 357 <= int(x) <= N and len(set(x)) == 3: +            ans += 1 +print(ans)