local n=io.read("n")
local t={3,5,7}
local i=1
while t[#t]<=n do
    for j=3,7,2 do
        t[#t+1]=t[i]*10+j
    end
    i=i+1
end
local counter=0
for i=1,#t do
    local three=false
    local five=false
    local seven=false
    local copy=t[i]
    while copy>0 do
        if copy%10==3 then three=true
        elseif copy%10==5 then five=true
        elseif copy%10==7 then seven=true
        end
        copy=math.floor(copy/10)
    end
    if three and five and seven and t[i]<=n then
        counter=counter+1
    end
end
print(counter)