import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int L = Integer.parseInt(br.readLine()); int N = Integer.parseInt(br.readLine()); String[] strW = br.readLine().split(" "); ArrayList W = new ArrayList(); int sum = 0; for (int i = 0; i < strW.length; i++) { W.add(Integer.parseInt(strW[i])); } W.sort(null); int i = 0; for (; i < W.size(); i++) { int tmpW = W.get(i); if (L >= tmpW) { L -= tmpW; } else { break; } } System.out.println(i); } }