n=int(eval(input()))

d=["3","5","7"]

ans=[]

ans+=d

while d:

    a=d.pop(0)

    if len(a)<9:

        for i in "357":

            d+=[i+a]

            ans+=[i+a]

ans=list(map(int,ans))

ans.sort()

print((sum(i<=n for i in ans if len(set(str(i)))==3)))
n=int(eval(input()))

d=["3","5","7"]

ans=0

while d:

    a=d.pop(0)

    if int(a)<=n and len(set(a))==3:ans+=1

    if len(a)<9:

        for i in "357":d+=[i+a]

print(ans)
n = int(eval(input()))
d = ["3", "5", "7"]
ans = []
ans += d
while d:
    a = d.pop(0)
    if len(a) < 9:
        for i in "357":
            d += [i + a]
            ans += [i + a]
ans = list(map(int, ans))
ans.sort()
print((sum(i <= n for i in ans if len(set(str(i))) == 3)))

n = int(eval(input()))
d = ["3", "5", "7"]
ans = 0
while d:
    a = d.pop(0)
    if int(a) <= n and len(set(a)) == 3:
        ans += 1
    if len(a) < 9:
        for i in "357":
            d += [i + a]
print(ans)

-ans = [] -ans += d +ans = 0 +    if int(a) <= n and len(set(a)) == 3: +        ans += 1 -            ans += [i + a] -ans = list(map(int, ans)) -ans.sort() -print((sum(i <= n for i in ans if len(set(str(i))) == 3))) +print(ans)