def Base_10_to_n(x,n):

	if (int(x/n)):

		return Base_10_to_n(int(x/n),n)+str(x%n)

	return str(x%n)

	

n=int(eval(input()))

l=len(str(n))



res=0



for i in range(4**l):

	x=Base_10_to_n(i,4)

	cnt=0

	if not "0" in x: 

		if ("3" in x) and ("2" in x) and ("1" in x):

			for j in range(len(x)):

				if x[j]=="1":

					cnt+=3*(10**j)

				elif x[j]=="2":

					cnt+=5*(10**j)

				elif x[j]=="3":

					cnt+=7*(10**j)

			if cnt<=n:

				res+=1

			

print(res)

		
n=int(eval(input()))

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

A=set(A)

cnt=0



for _ in range(len(str(n))-1):

	for a in list(A):

		x=a+"3"

		y=a+"5"

		z=a+"7"

		if int(x)<=n:

			A.add(x)

		if int(y)<=n:

			A.add(y)

		if int(z)<=n:

			A.add(z)



res=0



for a in list(A):

	if "3" in a and "5" in a and "7" in a:

		res+=1		



print(res)
def Base_10_to_n(x, n):
    if int(x / n):
        return Base_10_to_n(int(x / n), n) + str(x % n)
    return str(x % n)


n = int(eval(input()))
l = len(str(n))
res = 0
for i in range(4**l):
    x = Base_10_to_n(i, 4)
    cnt = 0
    if not "0" in x:
        if ("3" in x) and ("2" in x) and ("1" in x):
            for j in range(len(x)):
                if x[j] == "1":
                    cnt += 3 * (10**j)
                elif x[j] == "2":
                    cnt += 5 * (10**j)
                elif x[j] == "3":
                    cnt += 7 * (10**j)
            if cnt <= n:
                res += 1
print(res)

n = int(eval(input()))
A = ["3", "5", "7"]
A = set(A)
cnt = 0
for _ in range(len(str(n)) - 1):
    for a in list(A):
        x = a + "3"
        y = a + "5"
        z = a + "7"
        if int(x) <= n:
            A.add(x)
        if int(y) <= n:
            A.add(y)
        if int(z) <= n:
            A.add(z)
res = 0
for a in list(A):
    if "3" in a and "5" in a and "7" in a:
        res += 1
print(res)

-def Base_10_to_n(x, n): -    if int(x / n): -        return Base_10_to_n(int(x / n), n) + str(x % n) -    return str(x % n) - - -l = len(str(n)) +A = ["3", "5", "7"] +A = set(A) +cnt = 0 +for _ in range(len(str(n)) - 1): +    for a in list(A): +        x = a + "3" +        y = a + "5" +        z = a + "7" +        if int(x) <= n: +            A.add(x) +        if int(y) <= n: +            A.add(y) +        if int(z) <= n: +            A.add(z) -for i in range(4**l): -    x = Base_10_to_n(i, 4) -    cnt = 0 -    if not "0" in x: -        if ("3" in x) and ("2" in x) and ("1" in x): -            for j in range(len(x)): -                if x[j] == "1": -                    cnt += 3 * (10**j) -                elif x[j] == "2": -                    cnt += 5 * (10**j) -                elif x[j] == "3": -                    cnt += 7 * (10**j) -            if cnt <= n: -                res += 1 +for a in list(A): +    if "3" in a and "5" in a and "7" in a: +        res += 1