N = int(eval(input()))



def fes(cul='0'):

    if int(cul) > N:

        return 0 

    counter = 0

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

        counter += 1

    counter += fes(cul + "3")

    counter += fes(cul + "5")

    counter += fes(cul + "7")



    return counter



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



def fes(cul=0):

    if cul > N:

        return 0 

    counter = 0



    if "3" in str(cul) and "5" in str(cul) and "7" in str(cul):

        counter += 1

    counter += fes(cul * 10 + 3)

    counter += fes(cul * 10 + 5)

    counter += fes(cul * 10 + 7)



    return counter



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


def fes(cul="0"):
    if int(cul) > N:
        return 0
    counter = 0
    if "3" in cul and "5" in cul and "7" in cul:
        counter += 1
    counter += fes(cul + "3")
    counter += fes(cul + "5")
    counter += fes(cul + "7")
    return counter


print((fes()))

N = int(eval(input()))


def fes(cul=0):
    if cul > N:
        return 0
    counter = 0
    if "3" in str(cul) and "5" in str(cul) and "7" in str(cul):
        counter += 1
    counter += fes(cul * 10 + 3)
    counter += fes(cul * 10 + 5)
    counter += fes(cul * 10 + 7)
    return counter


print((fes()))

-def fes(cul="0"): -    if int(cul) > N: +def fes(cul=0): +    if cul > N: -    if "3" in cul and "5" in cul and "7" in cul: +    if "3" in str(cul) and "5" in str(cul) and "7" in str(cul): -    counter += fes(cul + "3") -    counter += fes(cul + "5") -    counter += fes(cul + "7") +    counter += fes(cul * 10 + 3) +    counter += fes(cul * 10 + 5) +    counter += fes(cul * 10 + 7)