import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { int L = Integer.parseInt(buff.readLine()); int N = Integer.parseInt(buff.readLine()); int[] box = new int[N]; String[] str = buff.readLine().split(" "); for (int i = 0; i < N; ++i) { box[i] = Integer.parseInt(str[i]); for (int j = 0; j < i; ++j) { if (box[i] < box[j]) { int w = box[i]; box[i] = box[j]; box[j] = w; } } } int ans = 0; int sum = 0; for (int i = 0; i < N; ++i) { sum += box[i]; if (sum > L) { break; } ++ans; } System.out.println(ans); } catch (NumberFormatException e) { } catch (IOException e) { } } }