#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<pair<int, int> > vii;
#define FOR(l) for(vi::iterator it=l.begin();it!=l.end();it++)
#define FOR_L(l, s, e) for(vi::iterator it=l.begin()+s;it!=l.end()-e;it++)
//----------Main source code -----------------//
int n, t, mSpaceLeft, sum;
vi d, ans, state;
void rcr(int i){
if(i==t){
if(n<mSpaceLeft){
ans.clear();
mSpaceLeft = n;
FOR(state)
ans.push_back(*it);
}
return;
}
//track i not chosen
rcr(i+1);
//or chosen
n-=d[i];
state.push_back(d[i]);
if(n>=0)
rcr(i+1);
n+=d[i];
state.pop_back();
}
int main() {
while(cin.good()&&cin>>n){
cin>>t;
mSpaceLeft = 99999999;
d.resize(t, 0);
for(int i=0;i<t;i++)
cin>>d[i];
rcr(0);
sum=0;
FOR(ans){
cout<<*it<<" ";
sum+=*it;
}
printf("sum:%d\n", sum);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIHN0ZDo6dmVjdG9yPGludD4gdmk7CnR5cGVkZWYgc3RkOjp2ZWN0b3I8cGFpcjxpbnQsIGludD4gPiB2aWk7CiNkZWZpbmUgRk9SKGwpIGZvcih2aTo6aXRlcmF0b3IgaXQ9bC5iZWdpbigpO2l0IT1sLmVuZCgpO2l0KyspCiNkZWZpbmUgRk9SX0wobCwgcywgZSkgZm9yKHZpOjppdGVyYXRvciBpdD1sLmJlZ2luKCkrcztpdCE9bC5lbmQoKS1lO2l0KyspCgovLy0tLS0tLS0tLS1NYWluIHNvdXJjZSBjb2RlIC0tLS0t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