def DFS(n):

    if len(n)>=3 and len(set(list(n))&{"3","5","7"})==3:

        A.append(int(n))

    if len(n)<10:

        for i in ("3","5","7"):

            DFS(n+i)





n=int(eval(input()))

A=[]

for i in ("3","5","7"):DFS(i)

A.sort()



cnt=0

while 1:

    if A[cnt]<=n:cnt +=1

    else:break

print(cnt)
def DFS(num):

    if 3<=len(num)<=m:

        if len(set(list(num)))==3:

            A.append(int(num))

    if len(num)<=m:

        for i in ["3","5","7"]:

            DFS(num+i)





n=eval(input())

m=len(n)

A=[]

for i in ["3","5","7"]:

    DFS(i)



cnt=0

for i in A:

    if i<=int(n):

        cnt +=1

print(cnt)
def DFS(n):
    if len(n) >= 3 and len(set(list(n)) & {"3", "5", "7"}) == 3:
        A.append(int(n))
    if len(n) < 10:
        for i in ("3", "5", "7"):
            DFS(n + i)


n = int(eval(input()))
A = []
for i in ("3", "5", "7"):
    DFS(i)
A.sort()
cnt = 0
while 1:
    if A[cnt] <= n:
        cnt += 1
    else:
        break
print(cnt)

def DFS(num):
    if 3 <= len(num) <= m:
        if len(set(list(num))) == 3:
            A.append(int(num))
    if len(num) <= m:
        for i in ["3", "5", "7"]:
            DFS(num + i)


n = eval(input())
m = len(n)
A = []
for i in ["3", "5", "7"]:
    DFS(i)
cnt = 0
for i in A:
    if i <= int(n):
        cnt += 1
print(cnt)

-def DFS(n): -    if len(n) >= 3 and len(set(list(n)) & {"3", "5", "7"}) == 3: -        A.append(int(n)) -    if len(n) < 10: -        for i in ("3", "5", "7"): -            DFS(n + i) +def DFS(num): +    if 3 <= len(num) <= m: +        if len(set(list(num))) == 3: +            A.append(int(num)) +    if len(num) <= m: +        for i in ["3", "5", "7"]: +            DFS(num + i) -n = int(eval(input())) +n = eval(input()) +m = len(n) -for i in ("3", "5", "7"): +for i in ["3", "5", "7"]: -A.sort() -while 1: -    if A[cnt] <= n: +for i in A: +    if i <= int(n): -    else: -        break