# -*- coding: utf-8 -*-



N = int(eval(input()))



ans = 0

cursor = "357"





def increment(cursor):

    l = len(cursor)

    ret = [''] * (l + 1)

    if cursor[-1] == '7':

        ret[-1] = '3'

        ret[-2] = '3'

    elif cursor[-1] == '5':

        ret[-1] = '7'

    elif cursor[-1] == '3':

        ret[-1] = '5'



    for i in range(l-1):

        if ret[-(2 + i)] == '3':

            if cursor[-(2 + i)] == '7':

                ret[-(2 + i)] = '3'

                ret[-(3 + i)] = '3'

            elif cursor[-(2 + i)] == '5':

                ret[-(2 + i)] = '7'

            elif cursor[-(2 + i)] == '3':

                ret[-(2 + i)] = '5'

        else:

            ret[-(2 + i)] = cursor[-(2 + i)]



    return ''.join(ret)





while N >= int(cursor):

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

        ans += 1

    cursor = increment(cursor)



print(ans)

from itertools import product



N = int(eval(input()))

ans, L = 0, len(str(N))

for i in range(L + 1):

    for p in product(("7", "5", "3"), repeat=i):

        if "7" in p and "5" in p and "3" in p:

            if (i == L and int(''.join(p)) <= N) or i < L:

                ans += 1

print(ans)

# -*- coding: utf-8 -*-
N = int(eval(input()))
ans = 0
cursor = "357"


def increment(cursor):
    l = len(cursor)
    ret = [""] * (l + 1)
    if cursor[-1] == "7":
        ret[-1] = "3"
        ret[-2] = "3"
    elif cursor[-1] == "5":
        ret[-1] = "7"
    elif cursor[-1] == "3":
        ret[-1] = "5"
    for i in range(l - 1):
        if ret[-(2 + i)] == "3":
            if cursor[-(2 + i)] == "7":
                ret[-(2 + i)] = "3"
                ret[-(3 + i)] = "3"
            elif cursor[-(2 + i)] == "5":
                ret[-(2 + i)] = "7"
            elif cursor[-(2 + i)] == "3":
                ret[-(2 + i)] = "5"
        else:
            ret[-(2 + i)] = cursor[-(2 + i)]
    return "".join(ret)


while N >= int(cursor):
    if "7" in cursor and "5" in cursor and "3" in cursor:
        ans += 1
    cursor = increment(cursor)
print(ans)

from itertools import product

N = int(eval(input()))
ans, L = 0, len(str(N))
for i in range(L + 1):
    for p in product(("7", "5", "3"), repeat=i):
        if "7" in p and "5" in p and "3" in p:
            if (i == L and int("".join(p)) <= N) or i < L:
                ans += 1
print(ans)

-# -*- coding: utf-8 -*- +from itertools import product + -ans = 0 -cursor = "357" - - -def increment(cursor): -    l = len(cursor) -    ret = [""] * (l + 1) -    if cursor[-1] == "7": -        ret[-1] = "3" -        ret[-2] = "3" -    elif cursor[-1] == "5": -        ret[-1] = "7" -    elif cursor[-1] == "3": -        ret[-1] = "5" -    for i in range(l - 1): -        if ret[-(2 + i)] == "3": -            if cursor[-(2 + i)] == "7": -                ret[-(2 + i)] = "3" -                ret[-(3 + i)] = "3" -            elif cursor[-(2 + i)] == "5": -                ret[-(2 + i)] = "7" -            elif cursor[-(2 + i)] == "3": -                ret[-(2 + i)] = "5" -        else: -            ret[-(2 + i)] = cursor[-(2 + i)] -    return "".join(ret) - - -while N >= int(cursor): -    if "7" in cursor and "5" in cursor and "3" in cursor: -        ans += 1 -    cursor = increment(cursor) +ans, L = 0, len(str(N)) +for i in range(L + 1): +    for p in product(("7", "5", "3"), repeat=i): +        if "7" in p and "5" in p and "3" in p: +            if (i == L and int("".join(p)) <= N) or i < L: +                ans += 1