#include<iostream>
#include<cstdio>
using namespace std;
int n,m,w[20],ans;
bool vis[20];
void dfs(int x,int sum){
if(x==n+1){
ans=max(ans,sum);
return;
}
if(sum+w[x]<=m)dfs(x+1,sum+w[x]);
dfs(x+1,sum);
}
int main(){
scanf("%d%d",&m,&n);
for(int i=1;i<=n;i++)scanf("%d",&w[i]);
dfs(1,0);
printf("%d",ans);
}