import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = Arrays.stream(sc.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); } }