N = int(eval(input()))

M = len(str(N))



def nsin(X,n):

    if(int(X/n)):

        return nsin(int(X/n),n)+str(X%n)

    return str(X%n)



res = 0

for m in range(3,M+1):

    for i in range(3 ** m):

        tri = nsin(i, 3).zfill(m)

        nl = []

        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:

            for j in range(m):

                if tri[j] == '0':

                    nl.append('3')

                elif tri[j] == '1':

                    nl.append('5')

                else:

                    nl.append('7')

            x = ''.join(nl)

            if int(x) <= N:

                res += 1



print(res)

N = int(eval(input()))

M = len(str(N))

res = [0]

def dfs(x):

    # 長さがMになったら終了

    if len(x) > M:

        return

    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0 and int(x) <= N:

        res[0] += 1

    dfs(x + '3')

    dfs(x + '5')

    dfs(x + '7')

    return



dfs('3')

dfs('5')

dfs('7')

print((res[0]))    

    
N = int(eval(input()))
M = len(str(N))


def nsin(X, n):
    if int(X / n):
        return nsin(int(X / n), n) + str(X % n)
    return str(X % n)


res = 0
for m in range(3, M + 1):
    for i in range(3**m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count("0") > 0 and tri.count("1") > 0 and tri.count("2") > 0:
            for j in range(m):
                if tri[j] == "0":
                    nl.append("3")
                elif tri[j] == "1":
                    nl.append("5")
                else:
                    nl.append("7")
            x = "".join(nl)
            if int(x) <= N:
                res += 1
print(res)

N = int(eval(input()))
M = len(str(N))
res = [0]


def dfs(x):
    # 長さがMになったら終了
    if len(x) > M:
        return
    if x.count("3") > 0 and x.count("5") > 0 and x.count("7") > 0 and int(x) <= N:
        res[0] += 1
    dfs(x + "3")
    dfs(x + "5")
    dfs(x + "7")
    return


dfs("3")
dfs("5")
dfs("7")
print((res[0]))

+res = [0] -def nsin(X, n): -    if int(X / n): -        return nsin(int(X / n), n) + str(X % n) -    return str(X % n) +def dfs(x): +    # 長さがMになったら終了 +    if len(x) > M: +        return +    if x.count("3") > 0 and x.count("5") > 0 and x.count("7") > 0 and int(x) <= N: +        res[0] += 1 +    dfs(x + "3") +    dfs(x + "5") +    dfs(x + "7") +    return -res = 0 -for m in range(3, M + 1): -    for i in range(3**m): -        tri = nsin(i, 3).zfill(m) -        nl = [] -        if tri.count("0") > 0 and tri.count("1") > 0 and tri.count("2") > 0: -            for j in range(m): -                if tri[j] == "0": -                    nl.append("3") -                elif tri[j] == "1": -                    nl.append("5") -                else: -                    nl.append("7") -            x = "".join(nl) -            if int(x) <= N: -                res += 1 -print(res) +dfs("3") +dfs("5") +dfs("7") +print((res[0]))