There are n different types of objects. You want to buy atleast one instance of each type of object. There are m people , each of them sells one set of objects at a certain price (price is for the set).
Each of these m people sells either nothing or all the objects in the set he has. Information of these m sellers is represented by matrix M of size m∗n . if Mi,j=1, it means that ith seller has one jth type of object in his set, otherwise Mi,j=0 . The ith seller will sell set of all his objects at price Ci.
You want to buy at least one object of each type (it is guaranteed that it is always possible to do so). Find the minimal cost needed to pay to achieve it.
Input
The first line contains two integers n,m separated by space. (1≤n×m≤500).
The (i+1)th (1≤i≤m) line contains (n+1) integers - Mi,1,Mi,2,Mi,3,…,Mi,n,Ci. (0≤Mi,j≤1,1≤Ci≤109).
Output
Output the minimal cost you should pay to buy at least one object of each type.
Buy from the 1 and 2 seller with cost 2+3=5.