import sys

sys.setrecursionlimit(10**8)

def ii(): return int(sys.stdin.readline())

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

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

def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j): return [[ini]*i for _ in range(j)]

def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#import bisect #bisect.bisect_left(B, a)

#from collections import defaultdict #d = defaultdict(int) d[key] += value

import itertools #list(accumulate(A))



N = ii()

l = []



for keta in range(3, 10):

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

        l.append(int(''.join(koho)))



l.sort()



ele = ['3', '5', '7']

cnt = 0

for num in l:

    if num > N:

        break

    num = str(num)

    if all(e in num for e in ele):

        cnt += 1



print(cnt)
import sys

sys.setrecursionlimit(10**8)

def ii(): return int(sys.stdin.readline())

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

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

def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j): return [[ini]*i for _ in range(j)]

def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

#import bisect #bisect.bisect_left(B, a)

#from collections import defaultdict #d = defaultdict(int) d[key] += value

#import itertools #list(accumulate(A))

#from collections import deque



## FlagをもたせたDFS



N = ii()

ele = [3, 5, 7]

l = []



def dfs(num, flag):

    if num > N:

        return 

    if flag == 7:

        l.append(num)

    num *= 10

    for i, e in enumerate(ele):

        dfs(num+e, flag | 1<<i)



dfs(0, 0)

print((len(l)))
import sys

sys.setrecursionlimit(10**8)


def ii():
    return int(sys.stdin.readline())


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


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


def li2(N):
    return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def dp2(ini, i, j):
    return [[ini] * i for _ in range(j)]


def dp3(ini, i, j, k):
    return [[[ini] * i for _ in range(j)] for _ in range(k)]


# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools  # list(accumulate(A))

N = ii()
l = []
for keta in range(3, 10):
    for koho in itertools.product(["3", "5", "7"], repeat=keta):
        l.append(int("".join(koho)))
l.sort()
ele = ["3", "5", "7"]
cnt = 0
for num in l:
    if num > N:
        break
    num = str(num)
    if all(e in num for e in ele):
        cnt += 1
print(cnt)

import sys

sys.setrecursionlimit(10**8)


def ii():
    return int(sys.stdin.readline())


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


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


def li2(N):
    return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def dp2(ini, i, j):
    return [[ini] * i for _ in range(j)]


def dp3(ini, i, j, k):
    return [[[ini] * i for _ in range(j)] for _ in range(k)]


# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# import itertools #list(accumulate(A))
# from collections import deque
## FlagをもたせたDFS
N = ii()
ele = [3, 5, 7]
l = []


def dfs(num, flag):
    if num > N:
        return
    if flag == 7:
        l.append(num)
    num *= 10
    for i, e in enumerate(ele):
        dfs(num + e, flag | 1 << i)


dfs(0, 0)
print((len(l)))

-import itertools  # list(accumulate(A)) +# import itertools #list(accumulate(A)) +# from collections import deque +## FlagをもたせたDFS +N = ii() +ele = [3, 5, 7] +l = [] -N = ii() -l = [] -for keta in range(3, 10): -    for koho in itertools.product(["3", "5", "7"], repeat=keta): -        l.append(int("".join(koho))) -l.sort() -ele = ["3", "5", "7"] -cnt = 0 -for num in l: + +def dfs(num, flag): -        break -    num = str(num) -    if all(e in num for e in ele): -        cnt += 1 -print(cnt) +        return +    if flag == 7: +        l.append(num) +    num *= 10 +    for i, e in enumerate(ele): +        dfs(num + e, flag | 1 << i) + + +dfs(0, 0) +print((len(l)))