N = int(eval(input()))

ans = 0



def dfs(i):

    global ans

    if int(i) > N:

        return

    if all(i.count(c) for c in '753'):

        ans += 1

    dfs(i + '3')

    dfs(i + '5')

    dfs(i + '7')

    

dfs('0')



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

ans = 0



def dfs(s):

    global ans

    if int(s) > N:

        return



    if s.count('7') and s.count('5') and s.count('3'):

        ans += 1

    

    dfs(s + '7')

    dfs(s + '5')

    dfs(s + '3')



dfs('0')



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


def dfs(i):
    global ans
    if int(i) > N:
        return
    if all(i.count(c) for c in "753"):
        ans += 1
    dfs(i + "3")
    dfs(i + "5")
    dfs(i + "7")


dfs("0")
print(ans)

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


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


dfs("0")
print(ans)

-def dfs(i): +def dfs(s): -    if int(i) > N: +    if int(s) > N: -    if all(i.count(c) for c in "753"): +    if s.count("7") and s.count("5") and s.count("3"): -    dfs(i + "3") -    dfs(i + "5") -    dfs(i + "7") +    dfs(s + "7") +    dfs(s + "5") +    dfs(s + "3")