import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args) { Scanner sc1 = new Scanner(System.in); int n = Integer.parseInt(sc1.next()); Scanner sc2 = new Scanner(System.in); int m = Integer.parseInt(sc2.next()); Scanner sc3 = new Scanner(System.in); int[] arr = Arrays.stream(sc3.nextLine().split(" ")) .mapToInt(Integer::parseInt) .toArray(); Arrays.sort(arr); int i = 0; int j = 0; for(i = 0; m > 0; i++) { j += arr[i]; if(j > n) { break; } m--; } System.out.println(i); } }