lista=[3,5,7]

count=0

lim=int(eval(input()))

while True:

    t=lista.pop(0)

    if t>lim:

        break

    c=list(str(t))

    if c.count("3") and c.count("5") and c.count("7"):

        count+=1

    lista.append(10*t+3)

    lista.append(10*t+5)

    lista.append(10*t+7)

print(count)
from collections import deque

lista=deque([3,5,7])

count=0

lim=int(eval(input()))

while True:

    t=lista.popleft()

    if t>lim:

        break

    c=list(str(t))

    if c.count("3") and c.count("5") and c.count("7"):

        count+=1

    lista.append(10*t+3)

    lista.append(10*t+5)

    lista.append(10*t+7)

print(count)
lista = [3, 5, 7]
count = 0
lim = int(eval(input()))
while True:
    t = lista.pop(0)
    if t > lim:
        break
    c = list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count += 1
    lista.append(10 * t + 3)
    lista.append(10 * t + 5)
    lista.append(10 * t + 7)
print(count)

from collections import deque

lista = deque([3, 5, 7])
count = 0
lim = int(eval(input()))
while True:
    t = lista.popleft()
    if t > lim:
        break
    c = list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count += 1
    lista.append(10 * t + 3)
    lista.append(10 * t + 5)
    lista.append(10 * t + 7)
print(count)

-lista = [3, 5, 7] +from collections import deque + +lista = deque([3, 5, 7]) -    t = lista.pop(0) +    t = lista.popleft()