N = int(eval(input()))



ans = 0

p = [0]

while p:

    k = p.pop()

    if k > N:

        continue

    if '7' in str(k) and '5' in str(k) and '3' in str(k):

        ans += 1

    p.extend([k*10+3, k*10+5, k*10+7])

print(ans)

import sys

sys.setrecursionlimit(10**5)

N = int(input())



def rec(num, use):

    if num > N:

        return 0



    i = 0

    if (use == 0b111):

        i = 1



    return rec(num*10+7, use | 0b100)\

         + rec(num*10+5, use | 0b010)\

         + rec(num*10+3, use | 0b001)\

         + i



print(rec(0,0))

N = int(eval(input()))
ans = 0
p = [0]
while p:
    k = p.pop()
    if k > N:
        continue
    if "7" in str(k) and "5" in str(k) and "3" in str(k):
        ans += 1
    p.extend([k * 10 + 3, k * 10 + 5, k * 10 + 7])
print(ans)

import sys

sys.setrecursionlimit(10**5)
N = int(input())


def rec(num, use):
    if num > N:
        return 0
    i = 0
    if use == 0b111:
        i = 1
    return (
        rec(num * 10 + 7, use | 0b100)
        + rec(num * 10 + 5, use | 0b010)
        + rec(num * 10 + 3, use | 0b001)
        + i
    )


print(rec(0, 0))

-N = int(eval(input())) -ans = 0 -p = [0] -while p: -    k = p.pop() -    if k > N: -        continue -    if "7" in str(k) and "5" in str(k) and "3" in str(k): -        ans += 1 -    p.extend([k * 10 + 3, k * 10 + 5, k * 10 + 7]) -print(ans) +import sys + +sys.setrecursionlimit(10**5) +N = int(input()) + + +def rec(num, use): +    if num > N: +        return 0 +    i = 0 +    if use == 0b111: +        i = 1 +    return ( +        rec(num * 10 + 7, use | 0b100) +        + rec(num * 10 + 5, use | 0b010) +        + rec(num * 10 + 3, use | 0b001) +        + i +    ) + + +print(rec(0, 0))