#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SZ(a) (int)(a).size() #define FOR(i,a,b) for (int i=(a); i<=(b); ++i) #define REP(i,n) for (int i=0; i<(n); ++i) #define ALL(c) c.begin(), c.end() #define CLR(c,n) memset(c, n, sizeof(c)) #define MCPY(d, s) memcpy(d, s, sizeof(d)) #define TR(it, c) for (auto it = c.begin();it != c.end(); ++it) #define CONTAIN(it, c) (c.find(it) != c.end()) typedef vector VI; typedef pair PII; template void checkmin(T &a, T b) { if (b void checkmax(T &a, T b) { if (b>a) a=b; } typedef long long LL; const int INF=0x3F3F3F3F; int l, n, w[10<<10]; int main(int argc, char *argv[]) { while (scanf("%d%d", &l, &n) == 2) { REP(i, n) scanf("%d", &w[i]); sort(w, w+n); int ans = 0; while (ans < n && l >= 0) l -= w[ans++]; if (l < 0) --ans; printf("%d\n", ans); } }