import random as rng

import itertools as it

import collections as col

import heapq as hq

import sys

import copy as cp

sys.setrecursionlimit(10**9)





def dump_impl(*objects):

    print(*objects, file=sys.stderr)





def dump_dummy(*objects):

    pass





dump = dump_impl if "DEBUG" in sys.argv else dump_dummy



N = int(input())

ans = 0

for m in range(10):

    for s in it.product("753", repeat=m):

        dump(s)

        if '3' in s and '5' in s and '7' in s and int("".join(s)) <= N:

            ans += 1

print(ans)

import random as rng

import itertools as it

import collections as col

import heapq as hq

import sys

import copy as cp

sys.setrecursionlimit(10**9)





def dump_impl(*objects):

    print(*objects, file=sys.stderr)





def dump_dummy(*objects):

    pass





dump = dump_impl if "DEBUG" in sys.argv else dump_dummy



N = int(input())



ans = 0

for n in range(3, 10):

    for l in it.product(["7", "5", "3"], repeat=n):

        if "7" not in l or "5" not in l or "3" not in l:

            continue

        M = int("".join(l))

        if M <= N:

            dump(M, ans)

            ans += 1

dump(N)

print(ans)

import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp

sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy
N = int(input())
ans = 0
for m in range(10):
    for s in it.product("753", repeat=m):
        dump(s)
        if "3" in s and "5" in s and "7" in s and int("".join(s)) <= N:
            ans += 1
print(ans)

import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp

sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy
N = int(input())
ans = 0
for n in range(3, 10):
    for l in it.product(["7", "5", "3"], repeat=n):
        if "7" not in l or "5" not in l or "3" not in l:
            continue
        M = int("".join(l))
        if M <= N:
            dump(M, ans)
            ans += 1
dump(N)
print(ans)

-for m in range(10): -    for s in it.product("753", repeat=m): -        dump(s) -        if "3" in s and "5" in s and "7" in s and int("".join(s)) <= N: +for n in range(3, 10): +    for l in it.product(["7", "5", "3"], repeat=n): +        if "7" not in l or "5" not in l or "3" not in l: +            continue +        M = int("".join(l)) +        if M <= N: +            dump(M, ans) +dump(N)