import itertools

N=int(eval(input()))

l=len(str(N))

s=set()

S='753'

for i in range(1,l+1):

    for j in itertools.product(S,repeat=i):

        s.add(int(''.join(j)))

li=sorted(s)

cnt=0

for i in range(len(li)):

    if(li[i]>N):

        break

    if('7' in str(li[i]) and '5' in str(li[i]) and '3' in str(li[i])):

        cnt+=1

print(cnt)
c='753'

def dfs(s,L):

    global c

    li.append(s)

    if(len(s)==L):

        return

    for i in range(3):

        dfs(s+c[i],L)



N=int(eval(input()))

L=len(str(N))

li=[]

dfs('',L)

ans=0

for x in li:

    if(x==''):

        continue

    if(int(x)<=N and '7' in x and '5' in x and '3' in x):

        ans+=1

print(ans)
import itertools

N = int(eval(input()))
l = len(str(N))
s = set()
S = "753"
for i in range(1, l + 1):
    for j in itertools.product(S, repeat=i):
        s.add(int("".join(j)))
li = sorted(s)
cnt = 0
for i in range(len(li)):
    if li[i] > N:
        break
    if "7" in str(li[i]) and "5" in str(li[i]) and "3" in str(li[i]):
        cnt += 1
print(cnt)

c = "753"


def dfs(s, L):
    global c
    li.append(s)
    if len(s) == L:
        return
    for i in range(3):
        dfs(s + c[i], L)


N = int(eval(input()))
L = len(str(N))
li = []
dfs("", L)
ans = 0
for x in li:
    if x == "":
        continue
    if int(x) <= N and "7" in x and "5" in x and "3" in x:
        ans += 1
print(ans)

-import itertools +c = "753" + + +def dfs(s, L): +    global c +    li.append(s) +    if len(s) == L: +        return +    for i in range(3): +        dfs(s + c[i], L) + -l = len(str(N)) -s = set() -S = "753" -for i in range(1, l + 1): -    for j in itertools.product(S, repeat=i): -        s.add(int("".join(j))) -li = sorted(s) -cnt = 0 -for i in range(len(li)): -    if li[i] > N: -        break -    if "7" in str(li[i]) and "5" in str(li[i]) and "3" in str(li[i]): -        cnt += 1 -print(cnt) +L = len(str(N)) +li = [] +dfs("", L) +ans = 0 +for x in li: +    if x == "": +        continue +    if int(x) <= N and "7" in x and "5" in x and "3" in x: +        ans += 1 +print(ans)