n=gets.split()
return puts 0 if n.join.to_i < 357
sum=0
(357..n.join.to_i).each do |i|
  i =i.to_s.split('')
  next if (i & ['0','1','2','4','6','8','9']).any?
  if i.include?('3') && i.include?('5') && i.include?('7')
    sum+=1
  end
end
puts sum