N = int(eval(input()))

from collections import deque



def solve(N):

    ans = 0

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

    n = d.popleft()

    while n<=N:

        if len(set(list(str(n))))==3:

            ans += 1

        for num in [3,5,7]:

            new = int(str(n)+str(num))

            d.append(new)

        n = d.popleft()

    return ans

print((solve(N)))
from collections import deque

def solve():

    N = int(eval(input()))

    ans = 0

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

    while len(d):

        n = d.popleft()

        for i in range(3,8,2):

            a = n*10+i

            if a<=N:

                if len(set(list(str(a))))==3:

                    ans += 1

                d.append(a)

    return ans

print((solve()))
N = int(eval(input()))
from collections import deque


def solve(N):
    ans = 0
    d = deque([3, 5, 7])
    n = d.popleft()
    while n <= N:
        if len(set(list(str(n)))) == 3:
            ans += 1
        for num in [3, 5, 7]:
            new = int(str(n) + str(num))
            d.append(new)
        n = d.popleft()
    return ans


print((solve(N)))

from collections import deque


def solve():
    N = int(eval(input()))
    ans = 0
    d = deque([3, 5, 7])
    while len(d):
        n = d.popleft()
        for i in range(3, 8, 2):
            a = n * 10 + i
            if a <= N:
                if len(set(list(str(a)))) == 3:
                    ans += 1
                d.append(a)
    return ans


print((solve()))

-N = int(eval(input())) -def solve(N): +def solve(): +    N = int(eval(input())) -    n = d.popleft() -    while n <= N: -        if len(set(list(str(n)))) == 3: -            ans += 1 -        for num in [3, 5, 7]: -            new = int(str(n) + str(num)) -            d.append(new) +    while len(d): +        for i in range(3, 8, 2): +            a = n * 10 + i +            if a <= N: +                if len(set(list(str(a)))) == 3: +                    ans += 1 +                d.append(a) -print((solve(N))) +print((solve()))