n = eval(input())



d_len = len(n)





def dfs(d):

    ret = 0

    if int(d) > int(n):

        return 0

    if all(i in d for i in ('357')):

        ret += 1

    for j in '357':

        ret += dfs(d + j)

    return ret





print((dfs('0')))
from collections import defaultdict, deque, Counter

from heapq import heappush, heappop, heapify

import math

import bisect

import random

from itertools import permutations, accumulate, combinations, product

import sys

import string

from bisect import bisect_left, bisect_right

from math import factorial, ceil, floor

from operator import mul

from functools import reduce





sys.setrecursionlimit(2147483647)

INF = 10 ** 20

def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

def I(): return int(sys.stdin.buffer.readline())

def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n): return [I() for i in range(n)]

def LIR(n): return [LI() for i in range(n)]

def SR(n): return [S() for i in range(n)]

def LSR(n): return [LS() for i in range(n)]

def SRL(n): return [list(S()) for i in range(n)]

def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007



n = I()



ret = 0

for l in range(1, len(str(n)) + 1):

    for i in product(*[('3', '5', '7') for _ in range(l)]):

        num = ''.join(i)

        if '3' not in num or '5' not in num or '7' not in num or int(num) > n:

            continue

        ret += 1





print(ret)

n = eval(input())
d_len = len(n)


def dfs(d):
    ret = 0
    if int(d) > int(n):
        return 0
    if all(i in d for i in ("357")):
        ret += 1
    for j in "357":
        ret += dfs(d + j)
    return ret


print((dfs("0")))

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10**20


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode("utf-8")


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]


mod = 1000000007
n = I()
ret = 0
for l in range(1, len(str(n)) + 1):
    for i in product(*[("3", "5", "7") for _ in range(l)]):
        num = "".join(i)
        if "3" not in num or "5" not in num or "7" not in num or int(num) > n:
            continue
        ret += 1
print(ret)

-n = eval(input()) -d_len = len(n) +from collections import defaultdict, deque, Counter +from heapq import heappush, heappop, heapify +import math +import bisect +import random +from itertools import permutations, accumulate, combinations, product +import sys +import string +from bisect import bisect_left, bisect_right +from math import factorial, ceil, floor +from operator import mul +from functools import reduce + +sys.setrecursionlimit(2147483647) +INF = 10**20 -def dfs(d): -    ret = 0 -    if int(d) > int(n): -        return 0 -    if all(i in d for i in ("357")): -        ret += 1 -    for j in "357": -        ret += dfs(d + j) -    return ret +def LI(): +    return list(map(int, sys.stdin.buffer.readline().split())) -print((dfs("0"))) +def I(): +    return int(sys.stdin.buffer.readline()) + + +def LS(): +    return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() + + +def S(): +    return sys.stdin.buffer.readline().rstrip().decode("utf-8") + + +def IR(n): +    return [I() for i in range(n)] + + +def LIR(n): +    return [LI() for i in range(n)] + + +def SR(n): +    return [S() for i in range(n)] + + +def LSR(n): +    return [LS() for i in range(n)] + + +def SRL(n): +    return [list(S()) for i in range(n)] + + +def MSRL(n): +    return [[int(j) for j in list(S())] for i in range(n)] + + +mod = 1000000007 +n = I() +ret = 0 +for l in range(1, len(str(n)) + 1): +    for i in product(*[("3", "5", "7") for _ in range(l)]): +        num = "".join(i) +        if "3" not in num or "5" not in num or "7" not in num or int(num) > n: +            continue +        ret += 1 +print(ret)