N = int(eval(input()))



def dfs(s):

    if int(s) > N:

        return 0

    ret = 1 if all(s.count(c) > 0 for c in '357') else 0

    for c in '357':

        ret += dfs(s + c)

    return ret



print((dfs('0')))
# coding: utf-8

import sys

import itertools



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

answer = 0

digit = len(str(N))

# 3, 5, 7だけでできた数を列挙

for d in range(3, digit+1):

    for x in itertools.product(['3', '5', '7'], repeat=d):

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

            continue

        y = int(''.join(x))

        if y <= N:

            answer += 1



print(answer)

N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "357") else 0
    for c in "357":
        ret += dfs(s + c)
    return ret


print((dfs("0")))

# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
answer = 0
digit = len(str(N))
# 3, 5, 7だけでできた数を列挙
for d in range(3, digit + 1):
    for x in itertools.product(["3", "5", "7"], repeat=d):
        if len(set(x)) != 3:
            continue
        y = int("".join(x))
        if y <= N:
            answer += 1
print(answer)

-N = int(eval(input())) +# coding: utf-8 +import sys +import itertools - -def dfs(s): -    if int(s) > N: -        return 0 -    ret = 1 if all(s.count(c) > 0 for c in "357") else 0 -    for c in "357": -        ret += dfs(s + c) -    return ret - - -print((dfs("0"))) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N = ir() +answer = 0 +digit = len(str(N)) +# 3, 5, 7だけでできた数を列挙 +for d in range(3, digit + 1): +    for x in itertools.product(["3", "5", "7"], repeat=d): +        if len(set(x)) != 3: +            continue +        y = int("".join(x)) +        if y <= N: +            answer += 1 +print(answer)