N = int(eval(input()))



def dfs(s):

    if int(s)>N: 

        return 0

    for c in list("753"):

        if s.count(c) < 1:

            ret = 0

            break

    else:

        ret = 1

    for c in list("753"):

        ret += dfs(s+c)

    return ret



print((dfs("0")))
from collections import deque



N = int(eval(input()))

ans = 0

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



while q:

    s = q.pop()

    str_s = str(s)

    ok = True

    ok &= "7" in str_s

    ok &= "5" in str_s

    ok &= "3" in str_s

    ok &= s <= N

    if ok:

        ans += 1

    if len(str_s) < 9:

        q.append(10*s + 3)

        q.append(10*s + 5)

        q.append(10*s + 7)



print(ans)

N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    for c in list("753"):
        if s.count(c) < 1:
            ret = 0
            break
    else:
        ret = 1
    for c in list("753"):
        ret += dfs(s + c)
    return ret


print((dfs("0")))

from collections import deque

N = int(eval(input()))
ans = 0
q = deque([7, 5, 3])
while q:
    s = q.pop()
    str_s = str(s)
    ok = True
    ok &= "7" in str_s
    ok &= "5" in str_s
    ok &= "3" in str_s
    ok &= s <= N
    if ok:
        ans += 1
    if len(str_s) < 9:
        q.append(10 * s + 3)
        q.append(10 * s + 5)
        q.append(10 * s + 7)
print(ans)

+from collections import deque + - - -def dfs(s): -    if int(s) > N: -        return 0 -    for c in list("753"): -        if s.count(c) < 1: -            ret = 0 -            break -    else: -        ret = 1 -    for c in list("753"): -        ret += dfs(s + c) -    return ret - - -print((dfs("0"))) +ans = 0 +q = deque([7, 5, 3]) +while q: +    s = q.pop() +    str_s = str(s) +    ok = True +    ok &= "7" in str_s +    ok &= "5" in str_s +    ok &= "3" in str_s +    ok &= s <= N +    if ok: +        ans += 1 +    if len(str_s) < 9: +        q.append(10 * s + 3) +        q.append(10 * s + 5) +        q.append(10 * s + 7) +print(ans)