n = (int)(eval(input()))



def f(s):

    ans = 0

    if (int)(s) > n:

        return 0

    for c in '753':

        num = (str)(s+c)

        if (int)(num) <= n:

            if num.count('3')and num.count('5') and num.count('7'):

                ans += 1

            ans += f(num)

    return ans

print((f('0')))

# python template for atcoder1

import sys

sys.setrecursionlimit(10**9)

input = sys.stdin.readline



N = int(eval(input()))





ans = 0





def check(s: str)->bool:

    return '3' in s and '5' in s and '7' in s





def dfs(s: str)->int:

    ret = 0

    if int(s) > N:

        return 0

    else:

        if check(s):

            ret += 1

        r3 = dfs(s+"3")

        r5 = dfs(s+"5")

        r7 = dfs(s+"7")



        ret += r3+r5+r7

    return ret





print((dfs("0")))

n = (int)(eval(input()))


def f(s):
    ans = 0
    if (int)(s) > n:
        return 0
    for c in "753":
        num = (str)(s + c)
        if (int)(num) <= n:
            if num.count("3") and num.count("5") and num.count("7"):
                ans += 1
            ans += f(num)
    return ans


print((f("0")))

# python template for atcoder1
import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(eval(input()))
ans = 0


def check(s: str) -> bool:
    return "3" in s and "5" in s and "7" in s


def dfs(s: str) -> int:
    ret = 0
    if int(s) > N:
        return 0
    else:
        if check(s):
            ret += 1
        r3 = dfs(s + "3")
        r5 = dfs(s + "5")
        r7 = dfs(s + "7")
        ret += r3 + r5 + r7
    return ret


print((dfs("0")))

-n = (int)(eval(input())) +# python template for atcoder1 +import sys + +sys.setrecursionlimit(10**9) +input = sys.stdin.readline +N = int(eval(input())) +ans = 0 -def f(s): -    ans = 0 -    if (int)(s) > n: -        return 0 -    for c in "753": -        num = (str)(s + c) -        if (int)(num) <= n: -            if num.count("3") and num.count("5") and num.count("7"): -                ans += 1 -            ans += f(num) -    return ans +def check(s: str) -> bool: +    return "3" in s and "5" in s and "7" in s -print((f("0"))) +def dfs(s: str) -> int: +    ret = 0 +    if int(s) > N: +        return 0 +    else: +        if check(s): +            ret += 1 +        r3 = dfs(s + "3") +        r5 = dfs(s + "5") +        r7 = dfs(s + "7") +        ret += r3 + r5 + r7 +    return ret + + +print((dfs("0")))