#0,7,5,3で選んでくる

x=[0,7,5,3]

a=[]

k=0



def new_num(c):

    global x

    d=0

    for i in range(9):

        d+=(10**i)*x[c[i]]

    return d



for i0 in range(4):

    for i1 in range(4):

        for i2 in range(4):

            for i3 in range(4):

                for i4 in range(4):

                    for i5 in range(4):

                        for i6 in range(4):

                            for i7 in range(4):

                                for i8 in range(4):

                                    l1=new_num([i0,i1,i2,i3,i4,i5,i6,i7,i8])

                                    l2=str(l1)

                                    if ("3" in l2) and ("5" in l2) and ("7" in l2) and ("0" not in l2):

                                        a.append(l1)

a.sort()

co=0

n=int(eval(input()))

for i in a:

    if i<=n:

        #print(i)

        co+=1

    else:

        break

print(co)

from itertools import product

n=int(eval(input()))

ans=[]

for i in range(3,10):

    l=list(product(["3","5","7"],repeat=i))

    for j in l:

        if len(set(j))==3:

            ans.append(int("".join(list(j))))



ans.sort()

m=len(ans)

l,r=0,m-1

while l+1<r:

    k=(l+r)//2

    if ans[k]<n:

        l=k

    elif ans[k]>n:

        r=k

    else:

        l,r=k,k

        break

if ans[l]==n:

    print((l+1))

elif ans[r]==n:

    print((r+1))

elif ans[l]>n:

    print(l)

elif ans[r]<n:

    print((r+1))

elif ans[l]<n:

    print((l+1))

#print(l,r)

#print(ans)

# 0,7,5,3で選んでくる
x = [0, 7, 5, 3]
a = []
k = 0


def new_num(c):
    global x
    d = 0
    for i in range(9):
        d += (10**i) * x[c[i]]
    return d


for i0 in range(4):
    for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    l1 = new_num([i0, i1, i2, i3, i4, i5, i6, i7, i8])
                                    l2 = str(l1)
                                    if (
                                        ("3" in l2)
                                        and ("5" in l2)
                                        and ("7" in l2)
                                        and ("0" not in l2)
                                    ):
                                        a.append(l1)
a.sort()
co = 0
n = int(eval(input()))
for i in a:
    if i <= n:
        # print(i)
        co += 1
    else:
        break
print(co)

from itertools import product

n = int(eval(input()))
ans = []
for i in range(3, 10):
    l = list(product(["3", "5", "7"], repeat=i))
    for j in l:
        if len(set(j)) == 3:
            ans.append(int("".join(list(j))))
ans.sort()
m = len(ans)
l, r = 0, m - 1
while l + 1 < r:
    k = (l + r) // 2
    if ans[k] < n:
        l = k
    elif ans[k] > n:
        r = k
    else:
        l, r = k, k
        break
if ans[l] == n:
    print((l + 1))
elif ans[r] == n:
    print((r + 1))
elif ans[l] > n:
    print(l)
elif ans[r] < n:
    print((r + 1))
elif ans[l] < n:
    print((l + 1))
# print(l,r)
# print(ans)

-# 0,7,5,3で選んでくる -x = [0, 7, 5, 3] -a = [] -k = 0 +from itertools import product - -def new_num(c): -    global x -    d = 0 -    for i in range(9): -        d += (10**i) * x[c[i]] -    return d - - -for i0 in range(4): -    for i1 in range(4): -        for i2 in range(4): -            for i3 in range(4): -                for i4 in range(4): -                    for i5 in range(4): -                        for i6 in range(4): -                            for i7 in range(4): -                                for i8 in range(4): -                                    l1 = new_num([i0, i1, i2, i3, i4, i5, i6, i7, i8]) -                                    l2 = str(l1) -                                    if ( -                                        ("3" in l2) -                                        and ("5" in l2) -                                        and ("7" in l2) -                                        and ("0" not in l2) -                                    ): -                                        a.append(l1) -a.sort() -co = 0 -for i in a: -    if i <= n: -        # print(i) -        co += 1 +ans = [] +for i in range(3, 10): +    l = list(product(["3", "5", "7"], repeat=i)) +    for j in l: +        if len(set(j)) == 3: +            ans.append(int("".join(list(j)))) +ans.sort() +m = len(ans) +l, r = 0, m - 1 +while l + 1 < r: +    k = (l + r) // 2 +    if ans[k] < n: +        l = k +    elif ans[k] > n: +        r = k +        l, r = k, k -print(co) +if ans[l] == n: +    print((l + 1)) +elif ans[r] == n: +    print((r + 1)) +elif ans[l] > n: +    print(l) +elif ans[r] < n: +    print((r + 1)) +elif ans[l] < n: +    print((l + 1)) +# print(l,r) +# print(ans)