

import sys

sys.setrecursionlimit(1000000)

input = sys.stdin.readline

##############################



N = int(eval(input()))



def dfs(next_value, value, count_flag, count):

    value += next_value

    int_value = int(value)



#    print(int_value)



    if int_value > N:

        return count



    if int_value >= 357:

        if count_flag == False:

            if len(set(list(value))) == 3:

                count_flag = True



        if count_flag:

            count += 1



    count = dfs('3', value, count_flag, count)

    count = dfs('5', value, count_flag, count)

    count = dfs('7', value, count_flag, count)



    return count





count = 0

value = ''



count = dfs('3', '', False, count)

count = dfs('5', '', False, count)

count = dfs('7', '', False, count)



print(count)




import sys

input = sys.stdin.readline

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

# A = [ int(input()) for _ in range(N) ]

##############################



N = int(eval(input()))



def dfs(X, bit, count):

    if bit == 7:

        if X <= N:

            count += 1



    if X >= N:

        return count





    count = dfs(X*10+7, bit|4, count)

    count = dfs(X*10+5, bit|2, count)

    count = dfs(X*10+3, bit|1, count)



    return count





count = dfs(0, 0, 0)

print(count)

import sys

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################
N = int(eval(input()))


def dfs(next_value, value, count_flag, count):
    value += next_value
    int_value = int(value)
    #    print(int_value)
    if int_value > N:
        return count
    if int_value >= 357:
        if count_flag == False:
            if len(set(list(value))) == 3:
                count_flag = True
        if count_flag:
            count += 1
    count = dfs("3", value, count_flag, count)
    count = dfs("5", value, count_flag, count)
    count = dfs("7", value, count_flag, count)
    return count


count = 0
value = ""
count = dfs("3", "", False, count)
count = dfs("5", "", False, count)
count = dfs("7", "", False, count)
print(count)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
# A = [ int(input()) for _ in range(N) ]
##############################
N = int(eval(input()))


def dfs(X, bit, count):
    if bit == 7:
        if X <= N:
            count += 1
    if X >= N:
        return count
    count = dfs(X * 10 + 7, bit | 4, count)
    count = dfs(X * 10 + 5, bit | 2, count)
    count = dfs(X * 10 + 3, bit | 1, count)
    return count


count = dfs(0, 0, 0)
print(count)

-sys.setrecursionlimit(1000000) +sys.setrecursionlimit(2147483647) +INF = float("inf") +MOD = 10**9 + 7 +# A = [ int(input()) for _ in range(N) ] -def dfs(next_value, value, count_flag, count): -    value += next_value -    int_value = int(value) -    #    print(int_value) -    if int_value > N: +def dfs(X, bit, count): +    if bit == 7: +        if X <= N: +            count += 1 +    if X >= N: -    if int_value >= 357: -        if count_flag == False: -            if len(set(list(value))) == 3: -                count_flag = True -        if count_flag: -            count += 1 -    count = dfs("3", value, count_flag, count) -    count = dfs("5", value, count_flag, count) -    count = dfs("7", value, count_flag, count) +    count = dfs(X * 10 + 7, bit | 4, count) +    count = dfs(X * 10 + 5, bit | 2, count) +    count = dfs(X * 10 + 3, bit | 1, count) -count = 0 -value = "" -count = dfs("3", "", False, count) -count = dfs("5", "", False, count) -count = dfs("7", "", False, count) +count = dfs(0, 0, 0)