#include <bits/stdc++.h>
#pragma comment(linker, "/STACK: 1024000000,1024000000")
using namespace std;
inline int getint() {
  int _x = 0;
  char _tc = getchar();
  while (_tc < '0' || _tc > '9') _tc = getchar();
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x;
}
long long a[12];
map<long long, int> m;
long long ans = 0, W;
void dfs(int w, long long nw) {
  if (!w) {
    ans = max(ans, nw);
    return;
  }
  for (long long i = 8, ct = min(a[w], (W - nw) / w); i; i--, ct--)
    dfs(w - 1, nw + max(0ll, w * ct));
}
int main() {
  ans = 0;
  scanf("%I64d", &W);
  for (int i = 1; i < 9; i++) scanf("%I64d", &a[i]);
  dfs(8, 0);
  printf("%I64d\n", ans);
  return 0;
}
