local n = tonumber(io.read())
local a = {3,5,7}
function dfs(s)
    if s>n then
        return 0
    end
    local t = s
    local rtn =0
    local e3=false
    local e5=false
  	local e7=false
  	local ee = true
    while t>0 do
        if t%10==3 then
            e3 = true
        elseif t%10==5 then
            e5=true
        elseif t%10==7 then
            e7=true
        else
            ee=false
        end
        t = t//10
    end
    if e3 and e5 and e7 then
        rtn = rtn+1
    end
    if ee then
        for i=1,3,1 do
            rtn = rtn + dfs(s*10+a[i])
        end
    end
    return rtn
end
print(dfs(0))

