N = int(eval(input()))

s = "357"

cnt = 0

for i in range(1,10):

    for j in range(3**i):

        n = j

        t = ""

        for k in range(i):

            t+=s[n%3]

            n//=3

        if len(set(t))!=3:continue

        if int(t)<=N:cnt+=1

print(cnt)
from collections import deque

N = int(eval(input()))

ans = 0

A = "357"

Q = deque(["3","5","7"])

while Q:

    q = Q.pop()

    x = int(q)

    if x>N:continue

    if len(set(q))==3:ans+=1

    for a in A:

        Q.append(q+a)

print(ans)
N = int(eval(input()))
s = "357"
cnt = 0
for i in range(1, 10):
    for j in range(3**i):
        n = j
        t = ""
        for k in range(i):
            t += s[n % 3]
            n //= 3
        if len(set(t)) != 3:
            continue
        if int(t) <= N:
            cnt += 1
print(cnt)

from collections import deque

N = int(eval(input()))
ans = 0
A = "357"
Q = deque(["3", "5", "7"])
while Q:
    q = Q.pop()
    x = int(q)
    if x > N:
        continue
    if len(set(q)) == 3:
        ans += 1
    for a in A:
        Q.append(q + a)
print(ans)

+from collections import deque + -s = "357" -cnt = 0 -for i in range(1, 10): -    for j in range(3**i): -        n = j -        t = "" -        for k in range(i): -            t += s[n % 3] -            n //= 3 -        if len(set(t)) != 3: -            continue -        if int(t) <= N: -            cnt += 1 -print(cnt) +ans = 0 +A = "357" +Q = deque(["3", "5", "7"]) +while Q: +    q = Q.pop() +    x = int(q) +    if x > N: +        continue +    if len(set(q)) == 3: +        ans += 1 +    for a in A: +        Q.append(q + a) +print(ans)