def is_753(n):

    n = str(n)

    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)





n = int(eval(input()))





v = [7, 5, 3]

li = []

prev = [7, 5, 3]



for i in range(9):

    tmp = []

    for j in v:

        for k in prev:

            tmp.append(k * 10 + j)

    prev = tmp

    li = li + prev



li = [x for x in li if is_753(x) and x <= n]



print((len(li)))
import sys

sys.setrecursionlimit(10**6)



N = int(eval(input()))

V = [3, 5, 7]



li = []





def rec(curr, use):

    if curr > N:

        return

    if use == 0b111:

        li.append(curr)

    for i, b in enumerate(V):

        rec(curr * 10 + b, use | max(1, i * 2))





rec(0, 0)



print((len(li)))
def is_753(n):
    n = str(n)
    return n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1


n = int(eval(input()))
v = [7, 5, 3]
li = []
prev = [7, 5, 3]
for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev
li = [x for x in li if is_753(x) and x <= n]
print((len(li)))

import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
V = [3, 5, 7]
li = []


def rec(curr, use):
    if curr > N:
        return
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)
print((len(li)))

-def is_753(n): -    n = str(n) -    return n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1 +import sys + +sys.setrecursionlimit(10**6) +N = int(eval(input())) +V = [3, 5, 7] +li = [] -n = int(eval(input())) -v = [7, 5, 3] -li = [] -prev = [7, 5, 3] -for i in range(9): -    tmp = [] -    for j in v: -        for k in prev: -            tmp.append(k * 10 + j) -    prev = tmp -    li = li + prev -li = [x for x in li if is_753(x) and x <= n] +def rec(curr, use): +    if curr > N: +        return +    if use == 0b111: +        li.append(curr) +    for i, b in enumerate(V): +        rec(curr * 10 + b, use | max(1, i * 2)) + + +rec(0, 0)