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

for i in range(3,10):

    for v in product('357',repeat=i):

        val = ''.join(v)

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

           cnt += 1



print(cnt)
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
for i in range(3, 10):
    for v in product("357", repeat=i):
        val = "".join(v)
        if int(val) <= N and "3" in val and "5" in val and "7" in val:
            cnt += 1
print(cnt)

+from itertools import product + - - -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(""))) +for i in range(3, 10): +    for v in product("357", repeat=i): +        val = "".join(v) +        if int(val) <= N and "3" in val and "5" in val and "7" in val: +            cnt += 1 +print(cnt)