import sys

sys.setrecursionlimit(100000)

n=int(eval(input()))

m=len(str(n))

L=[]

def dfs(i,num):

    if i==m+1:

        return

    if 0<i<m+1:

        if len(set(num))==3 and int(num)<=n:

            L.append(int(num))

    dfs(i+1,num+'3')

    dfs(i+1,num+'5')

    dfs(i+1,num+'7')

dfs(0,'')

print((len(L)))
n=int(eval(input()))

m=len(str(n))

r=0



def dfs(i,s):

    global r

    if len(set(s))==3 and int(s)<=n:

        r+=1

    if i==m:

        return

    dfs(i+1,'3'+s)

    dfs(i+1,'5'+s)

    dfs(i+1,'7'+s)



dfs(0,'')

print(r)
import sys

sys.setrecursionlimit(100000)
n = int(eval(input()))
m = len(str(n))
L = []


def dfs(i, num):
    if i == m + 1:
        return
    if 0 < i < m + 1:
        if len(set(num)) == 3 and int(num) <= n:
            L.append(int(num))
    dfs(i + 1, num + "3")
    dfs(i + 1, num + "5")
    dfs(i + 1, num + "7")


dfs(0, "")
print((len(L)))

n = int(eval(input()))
m = len(str(n))
r = 0


def dfs(i, s):
    global r
    if len(set(s)) == 3 and int(s) <= n:
        r += 1
    if i == m:
        return
    dfs(i + 1, "3" + s)
    dfs(i + 1, "5" + s)
    dfs(i + 1, "7" + s)


dfs(0, "")
print(r)

-import sys - -sys.setrecursionlimit(100000) -L = [] +r = 0 -def dfs(i, num): -    if i == m + 1: +def dfs(i, s): +    global r +    if len(set(s)) == 3 and int(s) <= n: +        r += 1 +    if i == m: -    if 0 < i < m + 1: -        if len(set(num)) == 3 and int(num) <= n: -            L.append(int(num)) -    dfs(i + 1, num + "3") -    dfs(i + 1, num + "5") -    dfs(i + 1, num + "7") +    dfs(i + 1, "3" + s) +    dfs(i + 1, "5" + s) +    dfs(i + 1, "7" + s) -print((len(L))) +print(r)