s = ["3", "5", "7"]

s2 = ["357", "375", "537", "573", "735", "753"]

s3 = []

s4 = []

s5 = []

s6 = []

s7 = []

s8 = []



def PowerGorilla(s_t, s_i):

    s_new = []

    for j in range(len(s_t)):

        for i in range(len(s_t[0])+1):

            for k in range(3):

                s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:])



    sss = list(set(s_new))

    return sss



s3 = PowerGorilla(s2, s)

s4 = PowerGorilla(s3, s)

s5 = PowerGorilla(s4, s)

s6 = PowerGorilla(s5, s)

s7 = PowerGorilla(s6, s)

s8 = PowerGorilla(s7, s)



#print(PowerGorilla(s8, s))



num = []

num.extend(int(i) for i in s2)

num.extend(int(i) for i in s3)

num.extend(int(i) for i in s4)

num.extend(int(i) for i in s5)

num.extend(int(i) for i in s6)

num.extend(int(i) for i in s7)

num.extend(int(i) for i in s8)



num.sort()



count = 0



n = int(eval(input()))

for i in range(len(num)):

    if num[i] <= n:

        count += 1



print(count) 
import itertools

n = eval(input())

dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]

#dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]



for i in range(len(n)):

    dp[i][0][0][0][0] = 1



for j in range(10):

    if int(n[0]) >= j:

        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1

dp[0][1][0][0][0] = 0



for i, j, k, l, m in itertools.product(list(range(len(n)-1)), list(range(2)), list(range(2)), list(range(2)), list(range(10))):

    if m in [3, 5, 7]:

        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]

        if m <= int(n[i+1]):

            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]



print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))

s = ["3", "5", "7"]
s2 = ["357", "375", "537", "573", "735", "753"]
s3 = []
s4 = []
s5 = []
s6 = []
s7 = []
s8 = []


def PowerGorilla(s_t, s_i):
    s_new = []
    for j in range(len(s_t)):
        for i in range(len(s_t[0]) + 1):
            for k in range(3):
                s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:])
    sss = list(set(s_new))
    return sss


s3 = PowerGorilla(s2, s)
s4 = PowerGorilla(s3, s)
s5 = PowerGorilla(s4, s)
s6 = PowerGorilla(s5, s)
s7 = PowerGorilla(s6, s)
s8 = PowerGorilla(s7, s)
# print(PowerGorilla(s8, s))
num = []
num.extend(int(i) for i in s2)
num.extend(int(i) for i in s3)
num.extend(int(i) for i in s4)
num.extend(int(i) for i in s5)
num.extend(int(i) for i in s6)
num.extend(int(i) for i in s7)
num.extend(int(i) for i in s8)
num.sort()
count = 0
n = int(eval(input()))
for i in range(len(num)):
    if num[i] <= n:
        count += 1
print(count)

import itertools

n = eval(input())
dp = [
    [[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]
    for l in range(len(n))
]
# dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]
for i in range(len(n)):
    dp[i][0][0][0][0] = 1
for j in range(10):
    if int(n[0]) >= j:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1
dp[0][1][0][0][0] = 0
for i, j, k, l, m in itertools.product(
    list(range(len(n) - 1)),
    list(range(2)),
    list(range(2)),
    list(range(2)),
    list(range(10)),
):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i + 1]):
            dp[i + 1][m == int(n[i + 1])][j or m == 3][k or m == 5][l or m == 7] += dp[
                i
            ][1][j][k][l]
print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))

-s = ["3", "5", "7"] -s2 = ["357", "375", "537", "573", "735", "753"] -s3 = [] -s4 = [] -s5 = [] -s6 = [] -s7 = [] -s8 = [] +import itertools - -def PowerGorilla(s_t, s_i): -    s_new = [] -    for j in range(len(s_t)): -        for i in range(len(s_t[0]) + 1): -            for k in range(3): -                s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:]) -    sss = list(set(s_new)) -    return sss - - -s3 = PowerGorilla(s2, s) -s4 = PowerGorilla(s3, s) -s5 = PowerGorilla(s4, s) -s6 = PowerGorilla(s5, s) -s7 = PowerGorilla(s6, s) -s8 = PowerGorilla(s7, s) -# print(PowerGorilla(s8, s)) -num = [] -num.extend(int(i) for i in s2) -num.extend(int(i) for i in s3) -num.extend(int(i) for i in s4) -num.extend(int(i) for i in s5) -num.extend(int(i) for i in s6) -num.extend(int(i) for i in s7) -num.extend(int(i) for i in s8) -num.sort() -count = 0 -n = int(eval(input())) -for i in range(len(num)): -    if num[i] <= n: -        count += 1 -print(count) +n = eval(input()) +dp = [ +    [[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)] +    for l in range(len(n)) +] +# dp[i桁目][nより小さいかどうか][3がある][5がある][7がある] +for i in range(len(n)): +    dp[i][0][0][0][0] = 1 +for j in range(10): +    if int(n[0]) >= j: +        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1 +dp[0][1][0][0][0] = 0 +for i, j, k, l, m in itertools.product( +    list(range(len(n) - 1)), +    list(range(2)), +    list(range(2)), +    list(range(2)), +    list(range(10)), +): +    if m in [3, 5, 7]: +        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l] +        if m <= int(n[i + 1]): +            dp[i + 1][m == int(n[i + 1])][j or m == 3][k or m == 5][l or m == 7] += dp[ +                i +            ][1][j][k][l] +print((dp[-1][0][1][1][1] + dp[-1][1][1][1][1]))