N = int(input())
count = 0
not_match_num = ['0','1','2','4','6','8','9']
if N<357:
    print(0)
else:
    for num in range(357, N):
        if '3' in str(num) and '5' in str(num) and '7' in str(num):
            for i in range(len(not_match_num)):
                if not_match_num[i]  in str(num):
                    break
            else:
                count += 1
print(count)