N = int(eval(input()))



dp = []



def dfs(x):

    if check(x):

        dp.append(x)



    if (x <= 10**9):

        dfs(10*x+3)

        dfs(10*x+5)

        dfs(10*x+7)



def check(x):

    set_x = set(list(str(x)))

    if set_x >= {'3','5','7'} and set_x <= {'3','5','7'}:

        return True





dfs(0)

print((len([item for item in dp if item <= N])))
N = int(eval(input()))

dp = []



def dfs(x):

    if len(set(str(x))) == 3:

        dp.append(x)



    if x < 10**9:

        dfs(x*10+3)

        dfs(x*10+5)

        dfs(x*10+7)



dfs(0)

print((len([item for item in dp if item <= N])))

N = int(eval(input()))
dp = []


def dfs(x):
    if check(x):
        dp.append(x)
    if x <= 10**9:
        dfs(10 * x + 3)
        dfs(10 * x + 5)
        dfs(10 * x + 7)


def check(x):
    set_x = set(list(str(x)))
    if set_x >= {"3", "5", "7"} and set_x <= {"3", "5", "7"}:
        return True


dfs(0)
print((len([item for item in dp if item <= N])))

N = int(eval(input()))
dp = []


def dfs(x):
    if len(set(str(x))) == 3:
        dp.append(x)
    if x < 10**9:
        dfs(x * 10 + 3)
        dfs(x * 10 + 5)
        dfs(x * 10 + 7)


dfs(0)
print((len([item for item in dp if item <= N])))

-    if check(x): +    if len(set(str(x))) == 3: -    if x <= 10**9: -        dfs(10 * x + 3) -        dfs(10 * x + 5) -        dfs(10 * x + 7) - - -def check(x): -    set_x = set(list(str(x))) -    if set_x >= {"3", "5", "7"} and set_x <= {"3", "5", "7"}: -        return True +    if x < 10**9: +        dfs(x * 10 + 3) +        dfs(x * 10 + 5) +        dfs(x * 10 + 7)