n = int(eval(input()))



def dfs(val, A):

    if val > n:

        return

    A.append(val)

    dfs(10 * val + 3, A)

    dfs(10 * val + 5, A)

    dfs(10 * val + 7, A)



A = []

dfs(3, A)

dfs(5, A)

dfs(7, A)



cnt = 0

for v in A:

    if len(set(list(str(v)))) == 3:

        cnt += 1

print(cnt)
# 7/3



# n 以下の「753数」の個数



n = int(eval(input()))



def dfs(val):

    # 終了条件

    if val > n:

        return



    A.append(val)



    for v in [3, 5, 7]:

        val = A.pop()

        dfs(10 * val + v)

        A.append(val)



A = []

for v in [3, 5, 7]:

    dfs(v)



res = 0

for v in A:

    s = str(v)

    if '3' in s and '5' in s and '7' in s:

        res += 1



print(res)
n = int(eval(input()))


def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)


A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)
cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)

# 7/3
# n 以下の「753数」の個数
n = int(eval(input()))


def dfs(val):
    # 終了条件
    if val > n:
        return
    A.append(val)
    for v in [3, 5, 7]:
        val = A.pop()
        dfs(10 * val + v)
        A.append(val)


A = []
for v in [3, 5, 7]:
    dfs(v)
res = 0
for v in A:
    s = str(v)
    if "3" in s and "5" in s and "7" in s:
        res += 1
print(res)

+# 7/3 +# n 以下の「753数」の個数 -def dfs(val, A): +def dfs(val): +    # 終了条件 -    dfs(10 * val + 3, A) -    dfs(10 * val + 5, A) -    dfs(10 * val + 7, A) +    for v in [3, 5, 7]: +        val = A.pop() +        dfs(10 * val + v) +        A.append(val) -dfs(3, A) -dfs(5, A) -dfs(7, A) -cnt = 0 +for v in [3, 5, 7]: +    dfs(v) +res = 0 -    if len(set(list(str(v)))) == 3: -        cnt += 1 -print(cnt) +    s = str(v) +    if "3" in s and "5" in s and "7" in s: +        res += 1 +print(res)