import sys



sys.setrecursionlimit(10 ** 9)

N = int(eval(input()))

length = len(str(N)) + 1

result = []





def dfs(now):

    if len(now) <= length and now != "":

        result.append(now)

        if len(now) == length:

            return

    dfs("3" + now)

    dfs("5" + now)

    dfs("7" + now)





dfs("")

ans = 0

result = set(result)

for r in result:

    i = int(r)

    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0:

        ans += 1

print(ans)

N = int(eval(input()))

nums = []

length = len(str(N))

def dfs(s, n):

        global nums

        nums.append(s)

        if n == length:

                return

        dfs(s + "3", n + 1)

        dfs(s + "5", n + 1)

        dfs(s + "7", n + 1)



dfs("", 0)

ans = 0

for i in nums:

        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:

                if int(i) <= N:

                        ans += 1

print(ans)
import sys

sys.setrecursionlimit(10**9)
N = int(eval(input()))
length = len(str(N)) + 1
result = []


def dfs(now):
    if len(now) <= length and now != "":
        result.append(now)
        if len(now) == length:
            return
    dfs("3" + now)
    dfs("5" + now)
    dfs("7" + now)


dfs("")
ans = 0
result = set(result)
for r in result:
    i = int(r)
    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0:
        ans += 1
print(ans)

N = int(eval(input()))
nums = []
length = len(str(N))


def dfs(s, n):
    global nums
    nums.append(s)
    if n == length:
        return
    dfs(s + "3", n + 1)
    dfs(s + "5", n + 1)
    dfs(s + "7", n + 1)


dfs("", 0)
ans = 0
for i in nums:
    if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
        if int(i) <= N:
            ans += 1
print(ans)

-import sys - -sys.setrecursionlimit(10**9) -length = len(str(N)) + 1 -result = [] +nums = [] +length = len(str(N)) -def dfs(now): -    if len(now) <= length and now != "": -        result.append(now) -        if len(now) == length: -            return -    dfs("3" + now) -    dfs("5" + now) -    dfs("7" + now) +def dfs(s, n): +    global nums +    nums.append(s) +    if n == length: +        return +    dfs(s + "3", n + 1) +    dfs(s + "5", n + 1) +    dfs(s + "7", n + 1) -dfs("") +dfs("", 0) -result = set(result) -for r in result: -    i = int(r) -    if i <= N and r.count("3") > 0 and r.count("5") > 0 and r.count("7") > 0: -        ans += 1 +for i in nums: +    if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1: +        if int(i) <= N: +            ans += 1