import java.util.Scanner import java.io.{BufferedReader,InputStreamReader} object no5{ def main(args:Array[String]):Unit={ val br = new BufferedReader(new InputStreamReader(System.in)) val w = br.readLine().toInt val n = br.readLine().toInt val list = br.readLine().split(" ").map(_.toInt).toList.sorted val res = for(i <- 1 to n; if list.take(i).sum <= w) yield list(i-1) println(res.size) } }