#include <bits/stdc++.h> #if 1 && defined(LOCAL) #include <LOCAL/LOCAL.hpp> #else #define debug(...) #define line #endif using namespace std; typedef long long ll; typedef long double ld; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } int main() { int L,N; cin>>L>>N; priority_queue<int,vector<int>,greater<int>>A; for(int i=0;i<N;i++){ int a; cin>>a; A.push(a); } for(int i=0;i<N;i++){ L-=A.top(); A.pop(); if(L<0){ cout<<i<<endl; return 0; } } cout<<N<<endl; }