Robotic Cow Herd

Each robot picks one model per location, and all K robots must differ somewhere; find the minimum total cost of K distinct robots.

Hard9HeapGreedyCombinatoricsSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Bessie wants to fool Farmer John with a herd of KK convincing robotic cows (1K1000001 \le K \le 100000).

Building a robotic cow is harder than it sounds. A robot has NN (1N1000001 \le N \le 100000) locations that take a microcontroller, and exactly one microcontroller must be connected at each location. At location ii Bessie picks one of the models available there, and each model has its own cost.

The herd only looks convincing if no two robots behave the same way. No two robots may use exactly the same set of microcontrollers: for every pair of robots there must be at least one location where the two use a different microcontroller model. Two models offered at the same location count as different models even when they cost the same. The input always provides enough models to build KK different robots.

Bessie wants her herd as cheap as possible. Find the minimum total cost of building KK robots.

Input

The first line contains NN and KK separated by a space.

Each of the next NN lines describes the models available at one location. Line ii starts with MiM_i (1Mi101 \le M_i \le 10), the number of models available at location ii, followed by MiM_i space separated integers Pi,1,,Pi,MiP_{i,1}, \dots, P_{i,M_i}, the costs of those models (1Pi,j1000000001 \le P_{i,j} \le 100000000).

Output

Print one line with the minimum total cost of building KK robots.