n = int(input())
l = ['3','5','7']
el = ['0','1','2','4','6','8','9']
res = 0

for i in range(357,n+1):
    #print(i)
    n = list(str(i))
    if ("3" in n and "5" in n and "7" in n) and (str(i) not in el):
        res += 1
else:
    print(res)