from itertools import product

n=int(eval(input()))

cnt=0

kazu=[3,5,7]

for j in range(3,10):

    kumiawase = list(product(kazu, repeat=j))

    for kumi in kumiawase:

        suuji=''

        for moji in kumi:

            suuji+=str(moji)

        if '3'  not in suuji:

            continue

        if '5'  not in suuji:

            continue

        if '7'  not in suuji:

            continue

        hantei=int(suuji)

        if hantei <=n:

            cnt+=1

print(cnt)
#桁DP

s = eval(input())

n = int(s)

keta = len(s)

# dp[i][j][k][l][smaller][other]

dp = [

    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]

    for _ in range(keta + 1)

]

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

kazu = [0, 3, 5, 7]

for i in range(keta):

    for j in range(2):

        for k in range(2):

            for l in range(2):

                for smaller in range(2):

                    nd = int(s[i])

                    for d in range(10):

                        ni = i + 1

                        nj = j

                        nk = k

                        nl = l

                        nsmaller = smaller

                        if d not in kazu:

                            continue

                        if d == 3:

                            nj = 1

                        if d == 5:

                            nk = 1

                        if d == 7:

                            nl = 1

                        if smaller == 0:

                            if d > nd:

                                continue

                            if d < nd:

                                nsmaller = 1

                        if d == 0:

                            if nj + nk + nl != 0:

                                continue

                        dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]

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

from itertools import product

n = int(eval(input()))
cnt = 0
kazu = [3, 5, 7]
for j in range(3, 10):
    kumiawase = list(product(kazu, repeat=j))
    for kumi in kumiawase:
        suuji = ""
        for moji in kumi:
            suuji += str(moji)
        if "3" not in suuji:
            continue
        if "5" not in suuji:
            continue
        if "7" not in suuji:
            continue
        hantei = int(suuji)
        if hantei <= n:
            cnt += 1
print(cnt)

# 桁DP
s = eval(input())
n = int(s)
keta = len(s)
# dp[i][j][k][l][smaller][other]
dp = [
    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    for _ in range(keta + 1)
]
dp[0][0][0][0][0] = 1
kazu = [0, 3, 5, 7]
for i in range(keta):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for smaller in range(2):
                    nd = int(s[i])
                    for d in range(10):
                        ni = i + 1
                        nj = j
                        nk = k
                        nl = l
                        nsmaller = smaller
                        if d not in kazu:
                            continue
                        if d == 3:
                            nj = 1
                        if d == 5:
                            nk = 1
                        if d == 7:
                            nl = 1
                        if smaller == 0:
                            if d > nd:
                                continue
                            if d < nd:
                                nsmaller = 1
                        if d == 0:
                            if nj + nk + nl != 0:
                                continue
                        dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller]
print((dp[keta][1][1][1][0] + dp[keta][1][1][1][1]))

-from itertools import product - -n = int(eval(input())) -cnt = 0 -kazu = [3, 5, 7] -for j in range(3, 10): -    kumiawase = list(product(kazu, repeat=j)) -    for kumi in kumiawase: -        suuji = "" -        for moji in kumi: -            suuji += str(moji) -        if "3" not in suuji: -            continue -        if "5" not in suuji: -            continue -        if "7" not in suuji: -            continue -        hantei = int(suuji) -        if hantei <= n: -            cnt += 1 -print(cnt) +# 桁DP +s = eval(input()) +n = int(s) +keta = len(s) +# dp[i][j][k][l][smaller][other] +dp = [ +    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] +    for _ in range(keta + 1) +] +dp[0][0][0][0][0] = 1 +kazu = [0, 3, 5, 7] +for i in range(keta): +    for j in range(2): +        for k in range(2): +            for l in range(2): +                for smaller in range(2): +                    nd = int(s[i]) +                    for d in range(10): +                        ni = i + 1 +                        nj = j +                        nk = k +                        nl = l +                        nsmaller = smaller +                        if d not in kazu: +                            continue +                        if d == 3: +                            nj = 1 +                        if d == 5: +                            nk = 1 +                        if d == 7: +                            nl = 1 +                        if smaller == 0: +                            if d > nd: +                                continue +                            if d < nd: +                                nsmaller = 1 +                        if d == 0: +                            if nj + nk + nl != 0: +                                continue +                        dp[ni][nj][nk][nl][nsmaller] += dp[i][j][k][l][smaller] +print((dp[keta][1][1][1][0] + dp[keta][1][1][1][1]))