import bisect

N = int(eval(input()))

S = set([7,5,3])

for i in range(8):

    for j in S.copy():

        for k in [7,5,3]:

            S.add(int(str(j)+str(k)))

S = list(sorted(S))

T = []

for i in S:

    if str(i).count('3') and str(i).count('5') and str(i).count('7'):

        T.append(i)

print((bisect.bisect_right(T,N)))
import bisect

N = int(eval(input()))

S = set([7,5,3])

for i in range(8):

    for j in S.copy():

        for k in [7,5,3]:

            S.add(10*j+k)

T = []

for i in S:

    if str(i).count('3') and str(i).count('5') and str(i).count('7'):

        T.append(i)

T.sort()

print((bisect.bisect_right(T,N)))
import bisect

N = int(eval(input()))
S = set([7, 5, 3])
for i in range(8):
    for j in S.copy():
        for k in [7, 5, 3]:
            S.add(int(str(j) + str(k)))
S = list(sorted(S))
T = []
for i in S:
    if str(i).count("3") and str(i).count("5") and str(i).count("7"):
        T.append(i)
print((bisect.bisect_right(T, N)))

import bisect

N = int(eval(input()))
S = set([7, 5, 3])
for i in range(8):
    for j in S.copy():
        for k in [7, 5, 3]:
            S.add(10 * j + k)
T = []
for i in S:
    if str(i).count("3") and str(i).count("5") and str(i).count("7"):
        T.append(i)
T.sort()
print((bisect.bisect_right(T, N)))

-            S.add(int(str(j) + str(k))) -S = list(sorted(S)) +            S.add(10 * j + k) +T.sort()