#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#define N 1010 using namespace std; int dp[N], path[N][N], w[N]; int main()
{
int v, n;
while(~scanf("%d", &v))
{
scanf("%d", &n);
memset(dp, , sizeof(dp));
memset(path, , sizeof(path));
for(int i = ; i <= n ;i++)
scanf("%d", &w[i]);
for(int i = n ; i >= ; i--)
{
for(int j = v ; j >= w[i] ; j--)
{
if(dp[j] <= dp[j - w[i]] + w[i])
{
dp[j] = dp[j - w[i]] + w[i];
path[i][j] = ;
}//path记录
}
}
int j = v;
for(int i = ; i <= n ; i++)
{
if(path[i][j])
{
printf("%d ", w[i]);
j -= w[i];
}
}//打印路径
printf("sum:%d\n", dp[v]);
}
return ;
}