def cnct(lint,lim):

    global list753

    global list357

    global list333

    lint1=str(lint)+"3"

    lint1int=int(lint1)

    if lint1int<=lim and not lint1int in list357:

        list357.add(lint1int)

        cnct(lint1int,lim)

    lint2=str(lint)+"5"

    lint2int=int(lint2)

    if lint2int<=lim and not lint2int in list357:

        list357.add(lint2int)

        cnct(lint2int,lim)

    lint3=str(lint)+"7"

    lint3int=int(lint3)

    if lint3int<=lim and not lint3int in list357:

        list357.add(lint3int)

        cnct(lint3int,lim) 

    lint4="3"+str(lint)

    lint4int=int(lint4)

    if lint4int<=lim and not lint4int in list357:

        list357.add(lint4int)

        cnct(lint4int,lim)

    lint5="5"+str(lint)

    lint5int=int(lint5)

    if lint5int<=lim and not lint5int in list357:

        list357.add(lint5int)

        cnct(lint5int,lim)

    lint6="7"+str(lint)

    lint6int=int(lint6)

    if lint6int<=lim and not lint6int in list357:

        list357.add(lint6int)

        cnct(lint6int,lim)

def D(lint):

    lista=list(str(lint))

    if lista.count("3") and lista.count("5") and lista.count("7"):

        return True

    else:

        return False



list753=[3,5,7]

list357=set()

k=int(eval(input()))

count=0

for b in list753:

    cnct(b,k)

list333=list(list357)

list333.sort()

for c in [x for x in list333]:

    if not D(c):

        list333.remove(c)

print((len(list333)))

def cnct(lint,lim):

    global list753

    global list357

    global list333

    lint1int=lint*10+3

    if lint1int<=lim and not lint1int in list357:

        list357.add(lint1int)

        cnct(lint1int,lim)

    lint2int=lint*10+5

    if lint2int<=lim and not lint2int in list357:

        list357.add(lint2int)

        cnct(lint2int,lim)

    lint3int=lint*10+7

    if lint3int<=lim and not lint3int in list357:

        list357.add(lint3int)

        cnct(lint3int,lim) 



def D(lint):

    lista=list(str(lint))

    if lista.count("3") and lista.count("5") and lista.count("7"):

        return True

    else:

        return False



list753=[3,5,7]

list357=set()

k=int(eval(input()))

for b in list753:

    cnct(b,k)

for c in [x for x in list357]:

    if not D(c):

        list357.remove(c)

print((len(list357)))
def cnct(lint, lim):
    global list753
    global list357
    global list333
    lint1 = str(lint) + "3"
    lint1int = int(lint1)
    if lint1int <= lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int, lim)
    lint2 = str(lint) + "5"
    lint2int = int(lint2)
    if lint2int <= lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int, lim)
    lint3 = str(lint) + "7"
    lint3int = int(lint3)
    if lint3int <= lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int, lim)
    lint4 = "3" + str(lint)
    lint4int = int(lint4)
    if lint4int <= lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int, lim)
    lint5 = "5" + str(lint)
    lint5int = int(lint5)
    if lint5int <= lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int, lim)
    lint6 = "7" + str(lint)
    lint6int = int(lint6)
    if lint6int <= lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int, lim)


def D(lint):
    lista = list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False


list753 = [3, 5, 7]
list357 = set()
k = int(eval(input()))
count = 0
for b in list753:
    cnct(b, k)
list333 = list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print((len(list333)))

def cnct(lint, lim):
    global list753
    global list357
    global list333
    lint1int = lint * 10 + 3
    if lint1int <= lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int, lim)
    lint2int = lint * 10 + 5
    if lint2int <= lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int, lim)
    lint3int = lint * 10 + 7
    if lint3int <= lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int, lim)


def D(lint):
    lista = list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False


list753 = [3, 5, 7]
list357 = set()
k = int(eval(input()))
for b in list753:
    cnct(b, k)
for c in [x for x in list357]:
    if not D(c):
        list357.remove(c)
print((len(list357)))

-    lint1 = str(lint) + "3" -    lint1int = int(lint1) +    lint1int = lint * 10 + 3 -    lint2 = str(lint) + "5" -    lint2int = int(lint2) +    lint2int = lint * 10 + 5 -    lint3 = str(lint) + "7" -    lint3int = int(lint3) +    lint3int = lint * 10 + 7 -    lint4 = "3" + str(lint) -    lint4int = int(lint4) -    if lint4int <= lim and not lint4int in list357: -        list357.add(lint4int) -        cnct(lint4int, lim) -    lint5 = "5" + str(lint) -    lint5int = int(lint5) -    if lint5int <= lim and not lint5int in list357: -        list357.add(lint5int) -        cnct(lint5int, lim) -    lint6 = "7" + str(lint) -    lint6int = int(lint6) -    if lint6int <= lim and not lint6int in list357: -        list357.add(lint6int) -        cnct(lint6int, lim) -count = 0 -list333 = list(list357) -list333.sort() -for c in [x for x in list333]: +for c in [x for x in list357]: -        list333.remove(c) -print((len(list333))) +        list357.remove(c) +print((len(list357)))