from functools import reduce

n = int(eval(input()))



ans = 0

def dfs(numl):

    global ans

    if 3 in numl and 5 in numl and 7 in numl and n >= reduce( lambda a,b:10*a+b, numl):

        ans += 1

    if len(str(n)) > len(numl):

        for i in [3,5,7]:

            dfs(numl+[i])



dfs([])

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



global ans

ans = 0



def dfs(s):

    global ans

    if s:

        if int(s) > n:

            return

    if s:

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

            ans += 1

    dfs(s + "3")

    dfs(s + "5")

    dfs(s + "7")



dfs("")





print(ans)
from functools import reduce

n = int(eval(input()))
ans = 0


def dfs(numl):
    global ans
    if (
        3 in numl
        and 5 in numl
        and 7 in numl
        and n >= reduce(lambda a, b: 10 * a + b, numl)
    ):
        ans += 1
    if len(str(n)) > len(numl):
        for i in [3, 5, 7]:
            dfs(numl + [i])


dfs([])
print(ans)

n = int(eval(input()))
global ans
ans = 0


def dfs(s):
    global ans
    if s:
        if int(s) > n:
            return
    if s:
        if "3" in s and "5" in s and "7" in s:
            ans += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")


dfs("")
print(ans)

-from functools import reduce - +global ans -def dfs(numl): +def dfs(s): -    if ( -        3 in numl -        and 5 in numl -        and 7 in numl -        and n >= reduce(lambda a, b: 10 * a + b, numl) -    ): -        ans += 1 -    if len(str(n)) > len(numl): -        for i in [3, 5, 7]: -            dfs(numl + [i]) +    if s: +        if int(s) > n: +            return +    if s: +        if "3" in s and "5" in s and "7" in s: +            ans += 1 +    dfs(s + "3") +    dfs(s + "5") +    dfs(s + "7") -dfs([]) +dfs("")