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 var res = 0 var sum = 0 do{ sum += list(res) res += 1 }while(sum <= w && res < n) if(w < sum) println(res-1) else println(res) } }