from itertools import product

N = int(eval(input()))

ans = 0

for k in range(3,11):

    for i in product([0,3,5,7],repeat=k):

        if set(i) != {3,5,7}:

            continue

        if sum([10**j*v for j,v  in enumerate(i)]) <= N:

            ans += 1

print(ans)

N = int(eval(input()))





def dfs(s):

    if int(s) > N:

        return 0

    ret = 1 if len(set(s)) == 4 else 0

    for i in ('3', '5', '7'):

        ret += dfs(s+i)

    return ret





print((dfs('0')))

from itertools import product

N = int(eval(input()))
ans = 0
for k in range(3, 11):
    for i in product([0, 3, 5, 7], repeat=k):
        if set(i) != {3, 5, 7}:
            continue
        if sum([10**j * v for j, v in enumerate(i)]) <= N:
            ans += 1
print(ans)

N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if len(set(s)) == 4 else 0
    for i in ("3", "5", "7"):
        ret += dfs(s + i)
    return ret


print((dfs("0")))

-from itertools import product +N = int(eval(input())) -N = int(eval(input())) -ans = 0 -for k in range(3, 11): -    for i in product([0, 3, 5, 7], repeat=k): -        if set(i) != {3, 5, 7}: -            continue -        if sum([10**j * v for j, v in enumerate(i)]) <= N: -            ans += 1 -print(ans) + +def dfs(s): +    if int(s) > N: +        return 0 +    ret = 1 if len(set(s)) == 4 else 0 +    for i in ("3", "5", "7"): +        ret += dfs(s + i) +    return ret + + +print((dfs("0")))