import java.util.*; class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList W = new ArrayList<>(); int L = in.nextInt(); int N = in.nextInt(); for(int i = 0; i < N; i++) { W.add(in.nextInt()); } Collections.sort(W); int i = 0; while(L >= 0 && i < N) { L = L - W.get(i); if(L >= 0) { i++; } else { break; } } System.out.println(i); } }