# 753数の列挙

# DFS

def make_753number(n):

    s = str(n)

    if '7' in s and '5' in s and '3' in s:

        n753.add(n)

    if n <= 10**9:

        make_753number(10 * n + 7)

        make_753number(10 * n + 5)

        make_753number(10 * n + 3)





n753 = set()

make_753number(0)

N = int(eval(input()))

print((len([1 for n in n753 if n <= N])))

N = int(input())

N753 = set()





def dfs(depth, s):

    if depth == 9:

        n = int(s)

        if '0' not in str(n) \

            and '3' in str(n) \

            and '5' in str(n) \

            and '7' in str(n):

            N753.add(n)

        return



    dfs(depth+1, s+'0')

    dfs(depth+1, s+'3')

    dfs(depth+1, s+'5')

    dfs(depth+1, s+'7')



dfs(0, '')



ans = len([n for n in N753 if n <= N])

print(ans)

# 753数の列挙
# DFS
def make_753number(n):
    s = str(n)
    if "7" in s and "5" in s and "3" in s:
        n753.add(n)
    if n <= 10**9:
        make_753number(10 * n + 7)
        make_753number(10 * n + 5)
        make_753number(10 * n + 3)


n753 = set()
make_753number(0)
N = int(eval(input()))
print((len([1 for n in n753 if n <= N])))

N = int(input())
N753 = set()


def dfs(depth, s):
    if depth == 9:
        n = int(s)
        if "0" not in str(n) and "3" in str(n) and "5" in str(n) and "7" in str(n):
            N753.add(n)
        return
    dfs(depth + 1, s + "0")
    dfs(depth + 1, s + "3")
    dfs(depth + 1, s + "5")
    dfs(depth + 1, s + "7")


dfs(0, "")
ans = len([n for n in N753 if n <= N])
print(ans)

-# 753数の列挙 -# DFS -def make_753number(n): -    s = str(n) -    if "7" in s and "5" in s and "3" in s: -        n753.add(n) -    if n <= 10**9: -        make_753number(10 * n + 7) -        make_753number(10 * n + 5) -        make_753number(10 * n + 3) +N = int(input()) +N753 = set() -n753 = set() -make_753number(0) -N = int(eval(input())) -print((len([1 for n in n753 if n <= N]))) +def dfs(depth, s): +    if depth == 9: +        n = int(s) +        if "0" not in str(n) and "3" in str(n) and "5" in str(n) and "7" in str(n): +            N753.add(n) +        return +    dfs(depth + 1, s + "0") +    dfs(depth + 1, s + "3") +    dfs(depth + 1, s + "5") +    dfs(depth + 1, s + "7") + + +dfs(0, "") +ans = len([n for n in N753 if n <= N]) +print(ans)