n = int(eval(input()))



ans = 0

t = [3, 5, 7]

while len(t) > 0:

    x = t.pop(0)

    if x * 10 + 3 <= n:

        t.append(x * 10 + 3)

        if x * 10 + 5 <= n:

            t.append(x * 10 + 5)

            if x * 10 + 7 <= n:

                t.append(x * 10 + 7)

    if 357 <= x <= n:

        s = str(x)

        if '3' in s and '5' in s and '7' in s:

            ans += 1

print(ans)

# https://img.atcoder.jp/abc114/editorial.pdf

N = int(eval(input()))





def dfs(s):  # 文字列 s で始まる七五三数の個数

    if int(s) > N:

        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  # s 自体が七五三数なら +1

    for c in '753':

        ret += dfs(s + c)

    return ret





print((dfs('0'))) # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく

n = int(eval(input()))
ans = 0
t = [3, 5, 7]
while len(t) > 0:
    x = t.pop(0)
    if x * 10 + 3 <= n:
        t.append(x * 10 + 3)
        if x * 10 + 5 <= n:
            t.append(x * 10 + 5)
            if x * 10 + 7 <= n:
                t.append(x * 10 + 7)
    if 357 <= x <= n:
        s = str(x)
        if "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)

# https://img.atcoder.jp/abc114/editorial.pdf
N = int(eval(input()))


def dfs(s):  # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0  # s 自体が七五三数なら +1
    for c in "753":
        ret += dfs(s + c)
    return ret


print((dfs("0")))  # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく

-n = int(eval(input())) -ans = 0 -t = [3, 5, 7] -while len(t) > 0: -    x = t.pop(0) -    if x * 10 + 3 <= n: -        t.append(x * 10 + 3) -        if x * 10 + 5 <= n: -            t.append(x * 10 + 5) -            if x * 10 + 7 <= n: -                t.append(x * 10 + 7) -    if 357 <= x <= n: -        s = str(x) -        if "3" in s and "5" in s and "7" in s: -            ans += 1 -print(ans) +# https://img.atcoder.jp/abc114/editorial.pdf +N = int(eval(input())) + + +def dfs(s):  # 文字列 s で始まる七五三数の個数 +    if int(s) > N: +        return 0 +    ret = 1 if all(s.count(c) > 0 for c in "753") else 0  # s 自体が七五三数なら +1 +    for c in "753": +        ret += dfs(s + c) +    return ret + + +print((dfs("0")))  # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく