import java.io.*; import java.util.*; class Main5 { public static int solve (int[] wides , int max) { int ret = 0 , sum = 0; for (int i = 0; i < wides.length; i++) { if (sum + wides[i] <= max) { sum += wides[i]; ret++; } else { break; } } return ret; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int max = Integer.parseInt(br.readLine()); int blockCnt = Integer.parseInt(br.readLine()); int[] wides = new int[blockCnt]; String[] str = br.readLine().split(" "); for (int i = 0; i < blockCnt; i++) { wides[i] = Integer.parseInt(str[i]); } Arrays.sort(wides); System.out.println(solve(wides , max)); } }