/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); List list = new ArrayList<>(); for (int i = 0;i < N;i++) { list.add(sc.nextInt()); } list.sort((s1, s2) -> s1.compareTo(s2)); int sum =0; int count = 0; for (Integer I:list) { sum += I; if (0 <= L - sum) count++; } System.out.println(count); } }