import java.util.Scanner import java.io.{BufferedReader,InputStreamReader} import scala.collection.mutable.ListBuffer object no5{ def main(args:Array[String]):Unit={ val scan = new Scanner(System.in) val w = scan.nextInt val n = scan.nextInt var list:ListBuffer[Int] = ListBuffer[Int]() for(i <- 1 to n ) list += scan.nextInt list = list.sorted val res = for(i <- 1 to n; if list.take(i).sum <= w) yield list(i-1) println(res.size) } }