
inn = int(input())

result = 0

if inn < 357:
    print(0)

else:
    for i in range(357, inn):

        str_i = str(i)

        if '3' in str_i and '5' in str_i and '7' in str_i:
            str_i = str_i.replace('3', '')
            str_i = str_i.replace('5', '')
            str_i = str_i.replace('7', '')

            if str_i == '':
                result += 1

    print(result)
