n = int(eval(input()))

q = [ 3, 5, 7 ]



ans = 0

while len(q) != 0:

    x = q.pop(0)

    for i in [ 3, 5 , 7]:

        y = 10 * x + i

        if ( y <= n):

            q.append(y)

            if '3' in str(y) and '5' in str(y) and '7' in str(y):

                ans += 1

print(ans)
n = int(eval(input()))



def dfs(l):

    return sum([

        # next

        dfs(10 * l + i) if (10 * l + i) <= n else 0

        for i in [3, 5, 7]] +

        # current

        [1 if '3' in str(l) and '5' in str(l) and '7' in str(l) else 0]

        )



print((dfs(0)))
n = int(eval(input()))
q = [3, 5, 7]
ans = 0
while len(q) != 0:
    x = q.pop(0)
    for i in [3, 5, 7]:
        y = 10 * x + i
        if y <= n:
            q.append(y)
            if "3" in str(y) and "5" in str(y) and "7" in str(y):
                ans += 1
print(ans)

n = int(eval(input()))


def dfs(l):
    return sum(
        [
            # next
            dfs(10 * l + i) if (10 * l + i) <= n else 0
            for i in [3, 5, 7]
        ]
        +
        # current
        [1 if "3" in str(l) and "5" in str(l) and "7" in str(l) else 0]
    )


print((dfs(0)))

-q = [3, 5, 7] -ans = 0 -while len(q) != 0: -    x = q.pop(0) -    for i in [3, 5, 7]: -        y = 10 * x + i -        if y <= n: -            q.append(y) -            if "3" in str(y) and "5" in str(y) and "7" in str(y): -                ans += 1 -print(ans) + + +def dfs(l): +    return sum( +        [ +            # next +            dfs(10 * l + i) if (10 * l + i) <= n else 0 +            for i in [3, 5, 7] +        ] +        + +        # current +        [1 if "3" in str(l) and "5" in str(l) and "7" in str(l) else 0] +    ) + + +print((dfs(0)))