#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 10000 * 201;
int f[N];
int n, m = N;
int k;
int main(){
cin >> k >> n;
int v;
memset(f, 0x3f, sizeof f);
f[0] = 0;
for(int i = 1; i <= n; ++i){
cin >> v;
for(int j = v; j <= m; ++j)
f[j] = min(f[j], f[j - v] + 1);
}
int it = 0;
while(f[it] <= k) ++it;
cout << it - 1 << endl;
return 0;
}