import math

n_in = int(eval(input()))





def sgs(n, a, s, s_temp):

    if a == math.ceil(math.log(n, 10)):

        c = 0

        for i in s:

            i_listed = list(map(int, list(str(i))))

            if 3 in i_listed and 5 in i_listed and 7 in i_listed:

                if i <= n:

                    c += 1

    else:

        a += 1

        temp = []

        for i in s_temp:

            s.append(10 * i + 3)

            s.append(10 * i + 5)

            s.append(10 * i + 7)

            temp.append(10 * i + 3)

            temp.append(10 * i + 5)

            temp.append(10 * i + 7)

        s_temp = temp

        c = sgs(n, a, s, s_temp)

    return c





ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])

print(ans)

import collections

N = int(eval(input()))





def generate(n):

    _list = []

    queue = collections.deque([0])

    while queue:

        _temp = queue.popleft()

        if _temp <= n and '3' in str(_temp) and '7' in str(_temp) and '5' in str(_temp):

            _list.append(_temp)

        if len(str(_temp)) > 9:

            break

        queue.append(_temp * 10 + 7)

        queue.append(_temp * 10 + 5)

        queue.append(_temp * 10 + 3)

    return _list





_list = generate(N)

print((len(_list)))

import math

n_in = int(eval(input()))


def sgs(n, a, s, s_temp):
    if a == math.ceil(math.log(n, 10)):
        c = 0
        for i in s:
            i_listed = list(map(int, list(str(i))))
            if 3 in i_listed and 5 in i_listed and 7 in i_listed:
                if i <= n:
                    c += 1
    else:
        a += 1
        temp = []
        for i in s_temp:
            s.append(10 * i + 3)
            s.append(10 * i + 5)
            s.append(10 * i + 7)
            temp.append(10 * i + 3)
            temp.append(10 * i + 5)
            temp.append(10 * i + 7)
        s_temp = temp
        c = sgs(n, a, s, s_temp)
    return c


ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])
print(ans)

import collections

N = int(eval(input()))


def generate(n):
    _list = []
    queue = collections.deque([0])
    while queue:
        _temp = queue.popleft()
        if _temp <= n and "3" in str(_temp) and "7" in str(_temp) and "5" in str(_temp):
            _list.append(_temp)
        if len(str(_temp)) > 9:
            break
        queue.append(_temp * 10 + 7)
        queue.append(_temp * 10 + 5)
        queue.append(_temp * 10 + 3)
    return _list


_list = generate(N)
print((len(_list)))

-import math +import collections -n_in = int(eval(input())) +N = int(eval(input())) -def sgs(n, a, s, s_temp): -    if a == math.ceil(math.log(n, 10)): -        c = 0 -        for i in s: -            i_listed = list(map(int, list(str(i)))) -            if 3 in i_listed and 5 in i_listed and 7 in i_listed: -                if i <= n: -                    c += 1 -    else: -        a += 1 -        temp = [] -        for i in s_temp: -            s.append(10 * i + 3) -            s.append(10 * i + 5) -            s.append(10 * i + 7) -            temp.append(10 * i + 3) -            temp.append(10 * i + 5) -            temp.append(10 * i + 7) -        s_temp = temp -        c = sgs(n, a, s, s_temp) -    return c +def generate(n): +    _list = [] +    queue = collections.deque([0]) +    while queue: +        _temp = queue.popleft() +        if _temp <= n and "3" in str(_temp) and "7" in str(_temp) and "5" in str(_temp): +            _list.append(_temp) +        if len(str(_temp)) > 9: +            break +        queue.append(_temp * 10 + 7) +        queue.append(_temp * 10 + 5) +        queue.append(_temp * 10 + 3) +    return _list -ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7]) -print(ans) +_list = generate(N) +print((len(_list)))