import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Set set = new TreeSet(); int len = sc.nextInt(), n = sc.nextInt(); for(int i = 0; i < n; i++){ set.add(sc.nextInt()); } int cnt = 0, sum = 0; for(int i : set){ sum += i; if(sum <= len){ cnt++; } else { break; } } System.out.println(cnt); } }