Ns = eval(input())

N = int(Ns)

Nl = len(Ns)

ret = set()

def doit(t, f , s, now):

    if t + f + s == 0:

        if int(now) <= N:

            ret.add(now)

        return

    if t > 0:

        doit(t - 1, f, s, now + str(3)) 

    if f > 0:

        doit(t, f - 1, s, now + str(5)) 

    if s > 0:

        doit(t, f, s - 1, now + str(7)) 

    

for seven in range(1, Nl - 1):

    for five in range(1, Nl - seven):

        least = Nl - seven - five

        for three in range(1, least + 1):

            doit(three, five, seven, '')



print((len(ret)))



Ns = eval(input())

N = int(Ns)

Nl = len(Ns)

ret = []

def doit(t, f , s, now):

    if t + f + s == 0:

        if int(now) <= N:

            ret.append(now)

        return

    if t > 0:

        doit(t - 1, f, s, now + str(3)) 

    if f > 0:

        doit(t, f - 1, s, now + str(5)) 

    if s > 0:

        doit(t, f, s - 1, now + str(7)) 

    

for seven in range(1, Nl - 1):

    for five in range(1, Nl - seven):

        least = Nl - seven - five

        for three in range(1, least + 1):

            doit(three, five, seven, '')



print((len(ret)))

Ns = eval(input())
N = int(Ns)
Nl = len(Ns)
ret = set()


def doit(t, f, s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.add(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3))
    if f > 0:
        doit(t, f - 1, s, now + str(5))
    if s > 0:
        doit(t, f, s - 1, now + str(7))


for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, "")
print((len(ret)))

Ns = eval(input())
N = int(Ns)
Nl = len(Ns)
ret = []


def doit(t, f, s, now):
    if t + f + s == 0:
        if int(now) <= N:
            ret.append(now)
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3))
    if f > 0:
        doit(t, f - 1, s, now + str(5))
    if s > 0:
        doit(t, f, s - 1, now + str(7))


for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, "")
print((len(ret)))

-ret = set() +ret = [] -            ret.add(now) +            ret.append(now)