#include #include #define rep(i,a) for(int i=0;i<(a);++i) const int MAX_N = 10000; int L, N, W[MAX_N]; int main() { scanf( "%d%d", &L, &N ); rep( i, N ) scanf( "%d", W+i ); std::sort( W, W+N ); int sum = 0; rep( i, N ) { if( sum+W[i] > L ) { printf( "%d\n", i ); return 0; } sum += W[i]; } printf( "%d\n", N ); return 0; }