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")))
import itertools



N = int(eval(input()))

ans = 0



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

    cand = list(["".join(x) for x in itertools.product("357", repeat=i)])

    for c in cand:

        if int(c) > N:

            continue

        elif all(c.count(s) > 0 for s in "357"):

            ans += 1



print(ans)

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")))

import itertools

N = int(eval(input()))
ans = 0
for i in range(3, len(str(N)) + 1):
    cand = list(["".join(x) for x in itertools.product("357", repeat=i)])
    for c in cand:
        if int(c) > N:
            continue
        elif all(c.count(s) > 0 for s in "357"):
            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): +    cand = list(["".join(x) for x in itertools.product("357", repeat=i)]) +    for c in cand: +        if int(c) > N: +            continue +        elif all(c.count(s) > 0 for s in "357"): +            ans += 1 +print(ans)