#解説AC,9割写経

n = int(eval(input()))

def dfs(s):

    if int(s)>n:

        return 0

    ret = 1 if all(s.count(c) > 0 for c in "753") else 0

    for c in "753":

        ret += dfs(s+c)

    return ret



print((dfs("0")))

def dfs(n,a,s):

    global ans

    temp = int(s)

    if temp > n:

        return

    if "7" in s and "5" in s and "3" in s and n>=temp:

        ans += 1

    for i in a:

        dfs(n,a,s+i)

ans = 0

a = ["7","5","3"]

n = int(eval(input()))

s = "0"

dfs(n,a,s)

print(ans)
# 解説AC,9割写経
n = int(eval(input()))


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


print((dfs("0")))

def dfs(n, a, s):
    global ans
    temp = int(s)
    if temp > n:
        return
    if "7" in s and "5" in s and "3" in s and n >= temp:
        ans += 1
    for i in a:
        dfs(n, a, s + i)


ans = 0
a = ["7", "5", "3"]
n = int(eval(input()))
s = "0"
dfs(n, a, s)
print(ans)

-# 解説AC,9割写経 -n = int(eval(input())) +def dfs(n, a, s): +    global ans +    temp = int(s) +    if temp > n: +        return +    if "7" in s and "5" in s and "3" in s and n >= temp: +        ans += 1 +    for i in a: +        dfs(n, a, s + i) -def dfs(s): -    if int(s) > n: -        return 0 -    ret = 1 if all(s.count(c) > 0 for c in "753") else 0 -    for c in "753": -        ret += dfs(s + c) -    return ret - - -print((dfs("0"))) +ans = 0 +a = ["7", "5", "3"] +n = int(eval(input())) +s = "0" +dfs(n, a, s) +print(ans)