import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int haba = sc.nextInt(),num = sc.nextInt(); ArrayList list = new ArrayList(); for(int i = 0 ; i < num ; i++)list.add(sc.nextInt()); Collections.sort(list); int count = 0 , kosu = 0; for(int i = 0; i < num ; i++) { count += list.get(i); if(count > haba)break; kosu++; if(count == haba)break; } System.out.println(kosu); } }