N = int(eval(input()))

A = []



def f(s):

    if s != '' and eval(s) > N:

        return 0

    if all(s.count(i) >= 1 for i in '753'):

        A.append(eval(s))

    for i in '753':

        f(s + i)



f('')

print((len(A)))

# print(sorted(A))
N = int(eval(input()))

A = []



def f(s):

    if int(s) > N:

        return 0

    if all(s.count(i) >= 1 for i in '753'):

        A.append(int(s))

    for i in '753':

        f(s + i)



f('0')

print((len(A)))

# print(sorted(A))
N = int(eval(input()))
A = []


def f(s):
    if s != "" and eval(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in "753"):
        A.append(eval(s))
    for i in "753":
        f(s + i)


f("")
print((len(A)))
# print(sorted(A))

N = int(eval(input()))
A = []


def f(s):
    if int(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in "753"):
        A.append(int(s))
    for i in "753":
        f(s + i)


f("0")
print((len(A)))
# print(sorted(A))

-    if s != "" and eval(s) > N: +    if int(s) > N: -        A.append(eval(s)) +        A.append(int(s)) -f("") +f("0")