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; while(count <= L && i < N){ count += ts.pollFirst(); if(count > L) { break; } i++; } System.out.println(i); } }