N=int(input())
cnt=0
 
for i in range(1, N+1):
    i=str(i)
    if "1" in i or "2" in i or "4" in i or "6" in i or "8" in i or "9" in i or "0" in i:
        continue
    elif "3" in i and "5" in i and "7" in i:
        cnt+=1
 
print(cnt)