import java.util.Scanner object no5{ def main(args:Array[String]):Unit={ val scan = new Scanner(System.in) val w = scan.nextInt() val n = scan.nextInt() val nums = for(i <- 1 to n) yield scan.nextInt() val list = nums.sorted var count = 0 var sum = 0 while(sum <= w){ sum += list(count) count += 1 } println(count-1) } }