#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#define cin fin
#define cout fout
using namespace std;
int main()
{
ifstream fin("npack.in");
ofstream fout("npack.out");
int n, m;
ios::sync_with_stdio(false);
cin >> m >> n;
int v[51], dp[20001];
for(int i = 1; i <= m; i ++)
dp[i] = 0;
for(int i = 1; i <= n; i ++)
cin >> v[i];
dp[0] = 1;
for(int i = 1; i <= n; i ++)
for(int j = m; j >= v[i]; --j)
dp[j] += dp[j - v[i]];
for(int i = m; i >= 0; i --)
{
if(dp[i] > 0)
{
cout << m - i << endl;
// system("pause");
return 0;
}
}
}