import java.util.Arrays; import java.util.Scanner; public class No00000005_Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int lineCnt = 0; int l = 0; int n = 0; String[] wi = null; while(scan.hasNextLine()) { lineCnt++; if(lineCnt == 1) { l = Integer.parseInt(scan.nextLine()); } else if(lineCnt == 2) { n = Integer.parseInt(scan.nextLine()); } else if(lineCnt == 3) { wi = scan.nextLine().split(" "); } if(lineCnt == 3) { break; } } Arrays.sort(wi); int cnt = 0; int sum = 0; for(int i = 0; i < n; i++) { int temp = Integer.parseInt(wi[i]); if(sum + temp > l) { break; } sum += temp; cnt++; } System.out.println(cnt); scan.close(); } }