import itertools

n=int(eval(input()))

ans=0



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

    for ptn in itertools.product((3,5,7),repeat=i):

        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):

            continue

        a=int("".join(list(map(str,ptn))))

        if a<=n:

            ans+=1

print(ans)

        
import itertools



n=int(eval(input()))

c=0

for i in range(len(str(n))+1):

      for j in list(itertools.product((3,5,7),repeat=i)):

            if (3 in j) and (5 in j) and (7 in j):

                  if n >=int((''.join(list(map(str,j))))):

                        c+=1

print(c)
import itertools

n = int(eval(input()))
ans = 0
for i in range(3, len(str(n)) + 1):
    for ptn in itertools.product((3, 5, 7), repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int("".join(list(map(str, ptn))))
        if a <= n:
            ans += 1
print(ans)

import itertools

n = int(eval(input()))
c = 0
for i in range(len(str(n)) + 1):
    for j in list(itertools.product((3, 5, 7), repeat=i)):
        if (3 in j) and (5 in j) and (7 in j):
            if n >= int(("".join(list(map(str, j))))):
                c += 1
print(c)

-ans = 0 -for i in range(3, len(str(n)) + 1): -    for ptn in itertools.product((3, 5, 7), repeat=i): -        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn): -            continue -        a = int("".join(list(map(str, ptn)))) -        if a <= n: -            ans += 1 -print(ans) +c = 0 +for i in range(len(str(n)) + 1): +    for j in list(itertools.product((3, 5, 7), repeat=i)): +        if (3 in j) and (5 in j) and (7 in j): +            if n >= int(("".join(list(map(str, j))))): +                c += 1 +print(c)