#include using namespace std; int n, m; vector > shops; int analyze_shop(int i, int limit){ set creams; int total = 0; int j = i; do{ int size = shops[j].size(); for(int q=0; q limit)break; j = (j+1) % n; }while(i!=j && creams.size() < m); return creams.size() < m ? -1 : total; } int main(){ ios::sync_with_stdio(false); while(scanf("%d %d\n", &n, &m) == 2) { shops.clear(); for(int i=0; i shop; int c; scanf("%d", &c); for(int j=0; j