N = int(input())

count = 0
for i in range(N):
    count3 = 0
    count5 = 0
    count7 = 0
    for j in range(len(str(i))):
        if int(str(i)[j]) == 3:
            count3 += 1
        elif int(str(i)[j]) == 5:
            count5 += 1
        elif int(str(i)[j]) == 7:
            count7 += 1
        else:
            break
        
    if count3>0 and count5>0 and count7>0 and count3+count5+count7 == len(str(i)):
        count += 1
print(count)