$n=gets.to_i

def dfs(n)
  return 0 if n > $n
  
  x = n.to_s.split('')
  sum =0
  # return if (n.split('') & ['0','1','2','4','6','8','9']).any?
  if x.include?('3') && x.include?('5') && x.include?('7') && x.all?{|a| a == "3" || a == "5" || a == "7"}
    sum+=1
  end
  sum+=dfs(3 + 10*n)
  sum+=dfs(5 + 10*n)
  sum+=dfs(7 + 10*n)
end
puts dfs(0)