#include <algorithm> #include <queue> #define REP(i,n) for(int i=0; i<(int)(n); i++) #include <cstdio> inline int getInt(){ int s; scanf("%d", &s); return s; } #include <set> using namespace std; int main(){ const int l = getInt(); const int n = getInt(); vector<int> w(n); REP(i,n) w[i] = getInt(); sort(w.begin(), w.end()); int a = 0; int ans = 0; REP(i,n) if(a + w[i] <= l){ a += w[i]; ans++; } printf("%d\n", ans); return 0; }