#include using namespace std; #define FOR(i, j, k) for(int i = j; i < k; ++i) #define rep(i, j) FOR(i, 0, j) #define repr(i, j) for(int i = j; i >= 0; -i) #define INF (1 << 30) #define MOD 1e9 + 7 typedef long long ll; typedef unsigned long long ull; typedef pair P; int L, N; vector W; int main(){ scanf("%d %d", &L, &N); rep(i, N) { int w; scanf("%d", &w); W.push_back(w); } sort(W.begin(), W.end()); int cnt = 0, now = 0; rep(i, N) { if(now + W[i] > L) break; now += W[i]; ++cnt; } printf("%d\n", cnt); return 0; }