constint maxn=10005; int n,K,w[30],sum,ans; multiset<int> S; typedefset<int>::iterator iter; intmain(){ scanf("%d%d",&n,&K); for (int i=1;i<=K;i++) scanf("%d",&w[i]),S.insert(w[i]),sum+=w[i]; ans=0x7fffffff; while (1){ if (S.size()>=n){ if (sum>=ans) break;else ans=sum; } int x=*S.begin();S.erase(S.begin());sum-=x; for (int i=1;i<=K;i++) S.insert(x+w[i]),sum+=x+w[i]; while (S.size()>n) sum-=*(--S.end()),S.erase(--S.end()); } printf("%d",ans); return0; }