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