#include <bits/stdc++.h>
using namespace std;
int main() {
  float beibao;
  int n, j;
  cin >> beibao >> n;
  float w[n + 1], sum, maxv = 0;
  int b[n + 1], i;
  for (i = 1; i <= n; i++) cin >> w[i];
  for (i = 0; i <= n; i++) b[i] = 0;
  while (b[0] == 0) {
    j = n;
    while (b[j] == 1) {
      b[j] = 0;
      j--;
    }
    b[j] = 1;
    sum = 0;
    for (i = 1; i <= n; i++) sum += w[i] * b[i];
    if (sum <= beibao && sum > maxv) maxv = sum;
  }
  cout << maxv << endl;
  return 0;
}
