import sys

sys.setrecursionlimit(100000)

N = int(eval(input()))

svt = []



def dfs(num):

    if num>1000000000:

        return

    #elif num<100:

    #    return

    else:

        svt.append(int(str(num)+'3'))

        dfs(int(str(num)+'3'))

        svt.append(int(str(num)+'5'))

        dfs(int(str(num)+'5'))

        svt.append(int(str(num)+'7'))

        dfs(int(str(num)+'7'))



def check753(num):

    exist3 = False

    exist5 = False

    exist7 = False

    s = str(num)

    for c in s:

        if c=='3':

            exist3 = True

        elif c=='5':

            exist5 = True

        elif c=='7':

            exist7 = True

    if exist3 and exist5 and exist7:

        return True

    else:

        return False





dfs(0)

svt = sorted(svt)

svt = svt[12:]

#print(svt)

count = 0

for i in range(len(svt)):

    if svt[i]>N:

        break

    if check753(svt[i]):

        count += 1

print(count)



N = int(eval(input()))



cnt = 0

def dfs(n):

    global cnt

    if n>N:

        return 0

    s = str(n)

    if '3' in s and '5' in s and '7' in s:

        cnt += 1

    dfs(int(s+'3'))

    dfs(int(s+'5'))

    dfs(int(s+'7'))



dfs(3)

dfs(5)

dfs(7)

print(cnt)

import sys

sys.setrecursionlimit(100000)
N = int(eval(input()))
svt = []


def dfs(num):
    if num > 1000000000:
        return
    # elif num<100:
    #    return
    else:
        svt.append(int(str(num) + "3"))
        dfs(int(str(num) + "3"))
        svt.append(int(str(num) + "5"))
        dfs(int(str(num) + "5"))
        svt.append(int(str(num) + "7"))
        dfs(int(str(num) + "7"))


def check753(num):
    exist3 = False
    exist5 = False
    exist7 = False
    s = str(num)
    for c in s:
        if c == "3":
            exist3 = True
        elif c == "5":
            exist5 = True
        elif c == "7":
            exist7 = True
    if exist3 and exist5 and exist7:
        return True
    else:
        return False


dfs(0)
svt = sorted(svt)
svt = svt[12:]
# print(svt)
count = 0
for i in range(len(svt)):
    if svt[i] > N:
        break
    if check753(svt[i]):
        count += 1
print(count)

N = int(eval(input()))
cnt = 0


def dfs(n):
    global cnt
    if n > N:
        return 0
    s = str(n)
    if "3" in s and "5" in s and "7" in s:
        cnt += 1
    dfs(int(s + "3"))
    dfs(int(s + "5"))
    dfs(int(s + "7"))


dfs(3)
dfs(5)
dfs(7)
print(cnt)

-import sys - -sys.setrecursionlimit(100000) -svt = [] +cnt = 0 -def dfs(num): -    if num > 1000000000: -        return -    # elif num<100: -    #    return -    else: -        svt.append(int(str(num) + "3")) -        dfs(int(str(num) + "3")) -        svt.append(int(str(num) + "5")) -        dfs(int(str(num) + "5")) -        svt.append(int(str(num) + "7")) -        dfs(int(str(num) + "7")) +def dfs(n): +    global cnt +    if n > N: +        return 0 +    s = str(n) +    if "3" in s and "5" in s and "7" in s: +        cnt += 1 +    dfs(int(s + "3")) +    dfs(int(s + "5")) +    dfs(int(s + "7")) -def check753(num): -    exist3 = False -    exist5 = False -    exist7 = False -    s = str(num) -    for c in s: -        if c == "3": -            exist3 = True -        elif c == "5": -            exist5 = True -        elif c == "7": -            exist7 = True -    if exist3 and exist5 and exist7: -        return True -    else: -        return False - - -dfs(0) -svt = sorted(svt) -svt = svt[12:] -# print(svt) -count = 0 -for i in range(len(svt)): -    if svt[i] > N: -        break -    if check753(svt[i]): -        count += 1 -print(count) +dfs(3) +dfs(5) +dfs(7) +print(cnt)