def func(S, num):

    ret = 0

    if '3' in S and '5' in S and '7' in S and int(S) <= num:

        ret += 1

    if len(S) == 10:

        return 0

    ret += func(S + '3', num)

    ret += func(S + '5', num)

    ret += func(S + '7', num)

    return ret



print(func('', eval(input())))
def func(S, num):

    if len(S) == 10:

        return 0

    ret = 0

    if '3' in S and '5' in S and '7' in S and int(S) <= num:

        ret += 1

    ret += func(S + '3', num)

    ret += func(S + '5', num)

    ret += func(S + '7', num)

    return ret



print(func('', eval(input())))
def func(S, num):
    ret = 0
    if "3" in S and "5" in S and "7" in S and int(S) <= num:
        ret += 1
    if len(S) == 10:
        return 0
    ret += func(S + "3", num)
    ret += func(S + "5", num)
    ret += func(S + "7", num)
    return ret


print(func("", eval(input())))

def func(S, num):
    if len(S) == 10:
        return 0
    ret = 0
    if "3" in S and "5" in S and "7" in S and int(S) <= num:
        ret += 1
    ret += func(S + "3", num)
    ret += func(S + "5", num)
    ret += func(S + "7", num)
    return ret


print(func("", eval(input())))

+    if len(S) == 10: +        return 0 -    if len(S) == 10: -        return 0