from collections import deque



N = int(eval(input()))



stack = deque()

num_753 = 0





def dfs():

    global stack, num_753



    s = stack.pop()



    if int(s) > N:

        return



    is_contained = 1 if all(s.count(c) > 0 for c in '753') else 0

    num_753 += is_contained



    for next_s in '357':

        stack.append(s + next_s)





stack.append('0')

while stack:

    dfs()



# Output

print(num_753)

# DP Solution (DP[...] = Bool if values which satisfy ... exist)

from itertools import product



N_str = input()

len_N = len(N_str)

N = int(N_str)



# DP Initialization

dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]

      for _ in range(len_N)]

# dp[digit][is_max][is_3][is_5][is_7]



# "non 3, 5, 7" and "not max" values exist

for l in range(len_N):

    dp[l][0][0][0][0] = 1





# DP at 0 digit

for m in range(10):

    digit_0 = int(N_str[0])

    if m > digit_0:

        continue

    if m in [3, 5, 7]:

        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1



# Current DP inherits last DP values

for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),

                             range(2)):

    if m in [3, 5, 7]:

        digit_lp1 = int(N_str[l + 1])

        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \

            dp[l][0][n][o][p]



        if digit_lp1 < m:

            continue



        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \

            dp[l][1][n][o][p]



print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])

from collections import deque

N = int(eval(input()))
stack = deque()
num_753 = 0


def dfs():
    global stack, num_753
    s = stack.pop()
    if int(s) > N:
        return
    is_contained = 1 if all(s.count(c) > 0 for c in "753") else 0
    num_753 += is_contained
    for next_s in "357":
        stack.append(s + next_s)


stack.append("0")
while stack:
    dfs()
# Output
print(num_753)

# DP Solution (DP[...] = Bool if values which satisfy ... exist)
from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)
# DP Initialization
dp = [
    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    for _ in range(len_N)
]
# dp[digit][is_max][is_3][is_5][is_7]
# "non 3, 5, 7" and "not max" values exist
for l in range(len_N):
    dp[l][0][0][0][0] = 1
# DP at 0 digit
for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if m in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1
# Current DP inherits last DP values
for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2), range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l + 1][0][n or m == 3][o or m == 5][p or m == 7] += dp[l][0][n][o][p]
        if digit_lp1 < m:
            continue
        dp[l + 1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += dp[l][1][n][
            o
        ][p]
print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])

-from collections import deque +# DP Solution (DP[...] = Bool if values which satisfy ... exist) +from itertools import product -N = int(eval(input())) -stack = deque() -num_753 = 0 - - -def dfs(): -    global stack, num_753 -    s = stack.pop() -    if int(s) > N: -        return -    is_contained = 1 if all(s.count(c) > 0 for c in "753") else 0 -    num_753 += is_contained -    for next_s in "357": -        stack.append(s + next_s) - - -stack.append("0") -while stack: -    dfs() -# Output -print(num_753) +N_str = input() +len_N = len(N_str) +N = int(N_str) +# DP Initialization +dp = [ +    [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] +    for _ in range(len_N) +] +# dp[digit][is_max][is_3][is_5][is_7] +# "non 3, 5, 7" and "not max" values exist +for l in range(len_N): +    dp[l][0][0][0][0] = 1 +# DP at 0 digit +for m in range(10): +    digit_0 = int(N_str[0]) +    if m > digit_0: +        continue +    if m in [3, 5, 7]: +        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1 +# Current DP inherits last DP values +for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2), range(2)): +    if m in [3, 5, 7]: +        digit_lp1 = int(N_str[l + 1]) +        dp[l + 1][0][n or m == 3][o or m == 5][p or m == 7] += dp[l][0][n][o][p] +        if digit_lp1 < m: +            continue +        dp[l + 1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += dp[l][1][n][ +            o +        ][p] +print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])