N = int(input())
N_list = []
N_753 = 0

for n in range(N):
    if n % 10 == 3 or 7 or 5:
        N_list.append(n)

for m in N_list:
    if all(x in str(m) for x in (str(7), str(5), str(3))) and not any(x in str(m) for x in (str(0), str(1), str(2), str(4), str(6), str(8), str(9))):
        N_753 +=1

print(N_753)