local n = io.read("n")
-- local n = 999999999
local total = 0
local stack = {{0,0}}
while true do
	local len = #stack
	local one = stack[len]
	if not one then
		break
	end
	local value, mark = one[1], one[2]
	table.remove(stack, len)
	if value <= n then
		if mark == 7 then
			total = total + 1
		end
		table.insert(stack, {value * 10 + 3, mark | 1})
		table.insert(stack, {value * 10 + 5, mark | 2})
		table.insert(stack, {value * 10 + 7, mark | 4})
	end
end
print(total)