#include using namespace std; typedef long long ll; #define MS(a) memset(a,0,sizeof(a)) #define MP make_pair #define PB push_back const int INF = 0x3f3f3f3f; const ll INFLL = 0x3f3f3f3f3f3f3f3fLL; inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ////////////////////////////////////////////////////////////////////////// const int maxn = 1e5+10; int n,m,k[1005],p[1005]; ll dp[1005]; int b[11][maxn],cnt[11]; int main(){ while(scanf("%d%d",&n,&m)!=EOF){ int mx = 0, mx2 = 0, mxblood=0; for(int i=0; i<11; i++) cnt[i]=0; for(int i=0; i= mx2){ puts("-1"); continue; } // cout << mxblood << endl; ll ans = 0; for(int d=0; d<11; d++){ if(cnt[d]==0) continue; int blood = mxblood; // for(int i=0; i<=m; i++) for(int j=0; j<=blood; j++) dp[j] = INFLL; for(int i=0; i<=m; i++) dp[0] = 0; for(int i=1; i<=m; i++){ if(p[i]