#include #include #include #include #include #include inline int get_how_many(const std::vector& W,std::unordered_map& how_many,int L){ if(how_many.end() == how_many.find(L)){ how_many[L] = std::numeric_limits::max(); for(auto w : W){ if(L - w >= 0){ how_many[L] = std::min(how_many[L],get_how_many(W,how_many,L-w)+1); } } } return how_many[L]; } int main(){ int L,N; std::vector W{}; std::unordered_map how_many{}; std::cin >> L >> N; how_many.reserve(L+1); W.reserve(N); std::copy_n(std::istream_iterator(std::cin),N,std::back_inserter(W)); how_many[0] = 0; std::cout << get_how_many(W,how_many,L) << std::endl; return 0; }