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('')と書きたいがint(s)でエラーを吐かないように仕方なく

N = int(eval(input()))

num_list = []





def dfs(num, add_num):

    num *= 10

    num += add_num



    if num > N:

        return



    num_list.append(num)



    dfs(num, 7)

    dfs(num, 5)

    dfs(num, 3)



    return num_list





dfs(3, 3)

dfs(3, 5)

dfs(3, 7)

dfs(5, 3)

dfs(5, 5)

dfs(5, 7)

dfs(7, 3)

dfs(7, 5)

dfs(7, 7)





ans = 0

tmp = 0

target = set(['7', '5', '3'])

# print(num_list)

for n in num_list:

    tmp = 0

    for t in target:

        if t in str(n):

            tmp += 1

    if tmp == 3:

        ans += 1

print(ans)

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('')と書きたいがint(s)でエラーを吐かないように仕方なく

N = int(eval(input()))
num_list = []


def dfs(num, add_num):
    num *= 10
    num += add_num
    if num > N:
        return
    num_list.append(num)
    dfs(num, 7)
    dfs(num, 5)
    dfs(num, 3)
    return num_list


dfs(3, 3)
dfs(3, 5)
dfs(3, 7)
dfs(5, 3)
dfs(5, 5)
dfs(5, 7)
dfs(7, 3)
dfs(7, 5)
dfs(7, 7)
ans = 0
tmp = 0
target = set(["7", "5", "3"])
# print(num_list)
for n in num_list:
    tmp = 0
    for t in target:
        if t in str(n):
            tmp += 1
    if tmp == 3:
        ans += 1
print(ans)

+num_list = [] -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 +def dfs(num, add_num): +    num *= 10 +    num += add_num +    if num > N: +        return +    num_list.append(num) +    dfs(num, 7) +    dfs(num, 5) +    dfs(num, 3) +    return num_list -print((dfs("0")))  # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく +dfs(3, 3) +dfs(3, 5) +dfs(3, 7) +dfs(5, 3) +dfs(5, 5) +dfs(5, 7) +dfs(7, 3) +dfs(7, 5) +dfs(7, 7) +ans = 0 +tmp = 0 +target = set(["7", "5", "3"]) +# print(num_list) +for n in num_list: +    tmp = 0 +    for t in target: +        if t in str(n): +            tmp += 1 +    if tmp == 3: +        ans += 1 +print(ans)