from itertools import product



n = int(eval(input()))

n_len = len(str(n))

ans = 0

for i in range(3,n_len):

    ite = product(list(range(3)),repeat=i)

    for it in ite:

        if 0 in it and 1 in it and 2 in it:

            ans += 1





num_d = {0:7,1:5,2:3}

ite = product(list(range(3)),repeat=n_len)

for it in ite:

    if 0 in it and 1 in it and 2 in it:

        curr_num = 0

        for i,j in enumerate(it):

            curr_num += num_d[j]*(10**(n_len-1-i))

        if curr_num <= n: 

            ans+=1



print(ans)
import sys

sys.setrecursionlimit(10**6)





def dfs(curr_num, e753, list753, n):

    if curr_num > n: return

    if e753 == 7:

        list753.append(curr_num)

    dfs(curr_num*10+7, e753|4, list753, n)

    dfs(curr_num*10+5, e753|2, list753, n)

    dfs(curr_num*10+3, e753|1, list753, n)





def main():

    n = int(eval(input()))

    list753 = []

    dfs(0,0,list753,n)

    print((len(list753)))





if __name__ == "__main__":

    main()
from itertools import product

n = int(eval(input()))
n_len = len(str(n))
ans = 0
for i in range(3, n_len):
    ite = product(list(range(3)), repeat=i)
    for it in ite:
        if 0 in it and 1 in it and 2 in it:
            ans += 1
num_d = {0: 7, 1: 5, 2: 3}
ite = product(list(range(3)), repeat=n_len)
for it in ite:
    if 0 in it and 1 in it and 2 in it:
        curr_num = 0
        for i, j in enumerate(it):
            curr_num += num_d[j] * (10 ** (n_len - 1 - i))
        if curr_num <= n:
            ans += 1
print(ans)

import sys

sys.setrecursionlimit(10**6)


def dfs(curr_num, e753, list753, n):
    if curr_num > n:
        return
    if e753 == 7:
        list753.append(curr_num)
    dfs(curr_num * 10 + 7, e753 | 4, list753, n)
    dfs(curr_num * 10 + 5, e753 | 2, list753, n)
    dfs(curr_num * 10 + 3, e753 | 1, list753, n)


def main():
    n = int(eval(input()))
    list753 = []
    dfs(0, 0, list753, n)
    print((len(list753)))


if __name__ == "__main__":
    main()

-from itertools import product +import sys -n = int(eval(input())) -n_len = len(str(n)) -ans = 0 -for i in range(3, n_len): -    ite = product(list(range(3)), repeat=i) -    for it in ite: -        if 0 in it and 1 in it and 2 in it: -            ans += 1 -num_d = {0: 7, 1: 5, 2: 3} -ite = product(list(range(3)), repeat=n_len) -for it in ite: -    if 0 in it and 1 in it and 2 in it: -        curr_num = 0 -        for i, j in enumerate(it): -            curr_num += num_d[j] * (10 ** (n_len - 1 - i)) -        if curr_num <= n: -            ans += 1 -print(ans) +sys.setrecursionlimit(10**6) + + +def dfs(curr_num, e753, list753, n): +    if curr_num > n: +        return +    if e753 == 7: +        list753.append(curr_num) +    dfs(curr_num * 10 + 7, e753 | 4, list753, n) +    dfs(curr_num * 10 + 5, e753 | 2, list753, n) +    dfs(curr_num * 10 + 3, e753 | 1, list753, n) + + +def main(): +    n = int(eval(input())) +    list753 = [] +    dfs(0, 0, list753, n) +    print((len(list753))) + + +if __name__ == "__main__": +    main()