$n = gets.chomp

n_size = $n.size

$n = $n.to_i

count = 0

def factorial(number)
  (1..number).inject(1,:*)
end

def x(i, remain, has3, has5, has7)
#	p [i, remain, has3, has5, has7]
	if remain == 1 then
		result = 0
		result += 1 if (i * 10 + 3) <= $n && has5 && has7
		result += 1 if (i * 10 + 5) <= $n && has3 && has7
		result += 1 if (i * 10 + 7) <= $n && has3 && has5
#		p ["result", result]
		result
	else
		x(i * 10 + 3, remain -1, true, has5, has7) +
		x(i * 10 + 5, remain -1, has3, true, has7) +
		x(i * 10 + 7, remain -1, has3, has5, true)
	end
end

(3..n_size).each{ |max|
	count += x(0, max, false, false, false)
}

puts count
