UP = int(1e9)

s = set()

full = set('357')





def dfs(n):

    if n > UP:

        return

    if set(str(n)) == full:

        s.add(n)

    dfs(n * 10 + 3)

    dfs(n * 10 + 5)

    dfs(n * 10 + 7)





dfs(0)

l = list(s)

l.sort()

n = int(eval(input()))

ans = 0

for i in l:

    if i <= n:

        ans += 1

    else:

        break

print(ans)

UP = int(1e9)

s = set()





def dfs(n, f3, f5, f7):

    if n > UP:

        return

    if f3 and f5 and f7:

        s.add(n)

    dfs(n * 10 + 3, True, f5, f7)

    dfs(n * 10 + 5, f3, True, f7)

    dfs(n * 10 + 7, f3, f5, True)





dfs(0, False, False, False)

l = list(s)

l.sort()

n = int(eval(input()))

ans = 0

for i in l:

    if i <= n:

        ans += 1

    else:

        break

print(ans)

UP = int(1e9)
s = set()
full = set("357")


def dfs(n):
    if n > UP:
        return
    if set(str(n)) == full:
        s.add(n)
    dfs(n * 10 + 3)
    dfs(n * 10 + 5)
    dfs(n * 10 + 7)


dfs(0)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)

UP = int(1e9)
s = set()


def dfs(n, f3, f5, f7):
    if n > UP:
        return
    if f3 and f5 and f7:
        s.add(n)
    dfs(n * 10 + 3, True, f5, f7)
    dfs(n * 10 + 5, f3, True, f7)
    dfs(n * 10 + 7, f3, f5, True)


dfs(0, False, False, False)
l = list(s)
l.sort()
n = int(eval(input()))
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)

-full = set("357") -def dfs(n): +def dfs(n, f3, f5, f7): -    if set(str(n)) == full: +    if f3 and f5 and f7: -    dfs(n * 10 + 3) -    dfs(n * 10 + 5) -    dfs(n * 10 + 7) +    dfs(n * 10 + 3, True, f5, f7) +    dfs(n * 10 + 5, f3, True, f7) +    dfs(n * 10 + 7, f3, f5, True) -dfs(0) +dfs(0, False, False, False)