local TernaryCounter = {}

function TernaryCounter.new()
    local self = setmetatable({}, {__index = TernaryCounter})
    self.count = {0}
    return self
end

function TernaryCounter:inc()
    local t = self.count
    local digits = #t
    t[1] = t[1] + 1
    for i=1,digits do
        if t[i] == 3 then
            t[i] = 0
            if t[i+1] == nil then
                t[i+1] = 0
            else
                t[i+1] = t[i+1] + 1
            end
        end
    end
    return self
end

function TernaryCounter:tonumber()
    local dic = {[0]=3, [1]=5, [2]=7}
    local t = self.count
    local ans = 0
    for i=#t,1,-1 do
        ans = ans * 10 + dic[t[i]]
    end
    return ans
end

function TernaryCounter:is753()
    local oc = {[0]=0, [1]=0, [2]=0}
    for _,v in ipairs(self.count) do
        oc[v] = oc[v] + 1
        if oc[0] > 0 and oc[1] > 0 and oc[2] > 0 then
            return true
        end
    end
    return false
end

local N = io.read("n")

local cntr = TernaryCounter.new()
local ans = 0
while true do
    local n = cntr:tonumber()
    if n > N then
        break
    end
    if cntr:is753() then
        ans = ans + 1
    end
    cntr:inc()
end
print(ans)
