#define _CRT_SECURE_NO_WARNINGS 1
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 10010
int main()
{
freopen("input.txt", "r", stdin);
int v, n;
while (~scanf("%d%d", &v, &n))
{
int cost[110];
int dp[maxn] = { 0 };
int used[maxn];
memset(used, -1, sizeof(used));
for (int i = 0; i < n; i++)
scanf("%d", &cost[i]);
for (int i = 0; i < n; i++)
{
for (int j = v; j >= cost[i]; j--)
{
if (dp[j - cost[i]] + cost[i] > dp[j])//如果可以更新最大值,那么更新
{
dp[j] = dp[j - cost[i]] + cost[i];
used[j] = cost[i]; //used用来记录这个点是由那个物品加之后过来的
}
}
}
int t = dp[v];
while (used[t] != -1)
{
printf("%d ", used[t]);
t -= used[t];
}
printf("sum:%d\n", dp[v]);
}
}