# -*- coding: utf-8 -*-                                                                              



N = int(eval(input()))



def count753(s):

    if int(s) > N:

        return 0

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

    for	c in "753":

        ret += count753(s + c)

    return ret



print((count753("0")))

from itertools import product



n = int(eval(input()))



ans = 0

for i in range(1, 10):

    for pat in product("357", repeat=i):

        num = "".join(pat)

        st = set(num)

        if int(num) <= n and st == {"3", "5", "7"}:

            ans += 1



print(ans)

# -*- coding: utf-8 -*-
N = int(eval(input()))


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


print((count753("0")))

from itertools import product

n = int(eval(input()))
ans = 0
for i in range(1, 10):
    for pat in product("357", repeat=i):
        num = "".join(pat)
        st = set(num)
        if int(num) <= n and st == {"3", "5", "7"}:
            ans += 1
print(ans)

-# -*- coding: utf-8 -*- -N = int(eval(input())) +from itertools import product - -def count753(s): -    if int(s) > N: -        return 0 -    ret = 1 if all(s.count(c) for c in "753") else 0 -    for c in "753": -        ret += count753(s + c) -    return ret - - -print((count753("0"))) +n = int(eval(input())) +ans = 0 +for i in range(1, 10): +    for pat in product("357", repeat=i): +        num = "".join(pat) +        st = set(num) +        if int(num) <= n and st == {"3", "5", "7"}: +            ans += 1 +print(ans)