import itertools



n=eval(input())



c=[]

for i in range(3,len(n)+1):

    c += list(itertools.product([3,5,7], repeat=i))



m=int(n)

ans=0

for i in range(len(c)):

    if 3 in c[i] and 5 in c[i] and 7 in c[i]:

        search=""

        for g in range(len(c[i])):

            search+=str(c[i][g])

        if m>=int(search):

            ans+=1

print(ans)

import bisect

def dfs(cnt, s, three, five, seven):

    if cnt == 10:

        return

    if s != "" and min(three, five, seven) > 0:

        v.append(int(s))

    dfs(cnt+1, "3"+s, three+1, five, seven)

    dfs(cnt+1, "5"+s, three, five+1, seven)

    dfs(cnt+1, "7"+s, three, five, seven+1)





v = []

dfs(0, "", 0, 0, 0)

v.sort()



n = int(eval(input()))

print((bisect.bisect_right(v, n)))
import itertools

n = eval(input())
c = []
for i in range(3, len(n) + 1):
    c += list(itertools.product([3, 5, 7], repeat=i))
m = int(n)
ans = 0
for i in range(len(c)):
    if 3 in c[i] and 5 in c[i] and 7 in c[i]:
        search = ""
        for g in range(len(c[i])):
            search += str(c[i][g])
        if m >= int(search):
            ans += 1
print(ans)

import bisect


def dfs(cnt, s, three, five, seven):
    if cnt == 10:
        return
    if s != "" and min(three, five, seven) > 0:
        v.append(int(s))
    dfs(cnt + 1, "3" + s, three + 1, five, seven)
    dfs(cnt + 1, "5" + s, three, five + 1, seven)
    dfs(cnt + 1, "7" + s, three, five, seven + 1)


v = []
dfs(0, "", 0, 0, 0)
v.sort()
n = int(eval(input()))
print((bisect.bisect_right(v, n)))

-import itertools +import bisect -n = eval(input()) -c = [] -for i in range(3, len(n) + 1): -    c += list(itertools.product([3, 5, 7], repeat=i)) -m = int(n) -ans = 0 -for i in range(len(c)): -    if 3 in c[i] and 5 in c[i] and 7 in c[i]: -        search = "" -        for g in range(len(c[i])): -            search += str(c[i][g]) -        if m >= int(search): -            ans += 1 -print(ans) + +def dfs(cnt, s, three, five, seven): +    if cnt == 10: +        return +    if s != "" and min(three, five, seven) > 0: +        v.append(int(s)) +    dfs(cnt + 1, "3" + s, three + 1, five, seven) +    dfs(cnt + 1, "5" + s, three, five + 1, seven) +    dfs(cnt + 1, "7" + s, three, five, seven + 1) + + +v = [] +dfs(0, "", 0, 0, 0) +v.sort() +n = int(eval(input())) +print((bisect.bisect_right(v, n)))