#include using namespace std; #define times(n, i) uptil(0, n, i) #define rtimes(n, i) downto((n) - 1, 0, i) #define upto(f, t, i) for(int i##_to_ = (t), i = (f); i <= i##_to_; i++) #define uptil(f, t, i) for(int i##_to_ = (t), i = (f); i < i##_to_; i++) #define downto(f, t, i) for(int i##_to_ = (t), i = (f); i >= i##_to_; i--) #define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i > i##_to_; i--) typedef long double LD; #define long long long #if defined(EBUG) && !defined(ONLINE_JUDGE) #define debug true #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 2 #define _LIBCPP_DEBUG2 2 #define ln << endl #else #define debug false #define ln << '\n' #endif #define tb << '\t' #define sp << ' ' signed main() { // long: 64bit if(!debug) { cin.tie(0); ios::sync_with_stdio(0); } int L, N; scanf("%d%d", &L, &N); vector W(N); times(N, i) scanf("%lld", &W[i]); sort(W.begin(), W.end()); long s = 0; times(N, i) { s += W[i]; if(s > L) { cout << i ln; return 0; } } cout << N ln; return 0; }