# coding: utf-8

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")))
# coding: utf-8

import itertools

N = int(eval(input()))

ans = 0



for i in range(3, len(str(N))+1):

    for ptn in itertools.product((3,5,7), repeat=i):

        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):

            continue

        a = int("".join(list(map(str, ptn))))

        if a <= N:

            ans += 1

print(ans)
# coding: utf-8
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")))

# coding: utf-8
import itertools

N = int(eval(input()))
ans = 0
for i in range(3, len(str(N)) + 1):
    for ptn in itertools.product((3, 5, 7), repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int("".join(list(map(str, ptn))))
        if a <= N:
            ans += 1
print(ans)

+import itertools + - - -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 +for i in range(3, len(str(N)) + 1): +    for ptn in itertools.product((3, 5, 7), repeat=i): +        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn): +            continue +        a = int("".join(list(map(str, ptn)))) +        if a <= N: +            ans += 1 +print(ans)