#coding: utf-8

from collections import Counter

N = int(eval(input()))

l = ["0", "3", "5", "7"]

ans = ["0" for _ in range(9)]

cnt = 0

for a in l:

    ans[0] = a

    for b in l:

        ans[1] = b

        for c in l:

            ans[2] = c

            for d in l:

                ans[3] = d

                for e in l:

                    ans[4] = e

                    for f in l:

                        ans[5] = f

                        for g in l:

                            ans[6] = g

                            for h in l:

                                ans[7] = h

                                for i in l:

                                    ans[8] = i

                                    ans_i = int("".join(ans))

                                    ans_c = Counter(str(ans_i))

                                    if ans_i <= N and "0" not in str(ans_i) and len(list(ans_c.keys())) == 3 and len(str(ans_i)) >= 3:

                                        cnt += 1

print(cnt)
#coding: utf-8

from collections import Counter

N = int(eval(input()))

l = ["0", "3", "5", "7"]

ans = ["0"] * 9

cnt = 0

for a in l:

    ans[0] = a

    for b in l:

        ans[1] = b

        for c in l:

            ans[2] = c

            for d in l:

                ans[3] = d

                for e in l:

                    ans[4] = e

                    for f in l:

                        ans[5] = f

                        for g in l:

                            ans[6] = g

                            for h in l:

                                ans[7] = h

                                for i in l:

                                    ans[8] = i

                                    ans_i = int("".join(ans))

                                    ans_c = Counter(str(ans_i))

                                    if ans_i <= N and "0" not in str(ans_i) and len(list(ans_c.keys())) == 3 and len(str(ans_i)) >= 3:

                                        cnt += 1

print(cnt)
# coding: utf-8
from collections import Counter

N = int(eval(input()))
l = ["0", "3", "5", "7"]
ans = ["0" for _ in range(9)]
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if (
                                        ans_i <= N
                                        and "0" not in str(ans_i)
                                        and len(list(ans_c.keys())) == 3
                                        and len(str(ans_i)) >= 3
                                    ):
                                        cnt += 1
print(cnt)

# coding: utf-8
from collections import Counter

N = int(eval(input()))
l = ["0", "3", "5", "7"]
ans = ["0"] * 9
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if (
                                        ans_i <= N
                                        and "0" not in str(ans_i)
                                        and len(list(ans_c.keys())) == 3
                                        and len(str(ans_i)) >= 3
                                    ):
                                        cnt += 1
print(cnt)

-ans = ["0" for _ in range(9)] +ans = ["0"] * 9