import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class No5 { public static void main(String[] args) { Scanner s = new Scanner(System.in); ArrayList W = new ArrayList<>(); int L = Integer.parseInt(s.nextLine()),N = Integer.parseInt(s.nextLine()),i = 0,count = 0; for(i = 0;i < N;i++) { W.add(Integer.parseInt(s.next())); } s.close(); i = 0; Collections.sort(W); for(int w : W) { L = L - w; if(L < 0) { break; }else { i++; } } System.out.println(i); } }