Alice is starting a new hobby! She has
A collection will not contain multiple of a single type of stamp. The collection will either have it or it will not.
Constraints
Input Specification
The first line contains two space-separated integers,
The second line contains
The next 0
or 1
. Each line represents the collection of one of Alice's friends. If the 0
, the 1
, the stamp type is in the collection.
Output Specification
Output -1
if it is not possible for Alice to build such a collection. Otherwise, output the minimum cost of such a collection.
Sample Input 1
3 2
2 3
1 0
0 1
1 0
Sample Output 1
5
Explanation for Sample 1
Alice should purchase both stamp types.
Between her first friend and this collection, only stamp type
Between her second friend and this collection, only stamp type
Between her third friend and this collection, only stamp type
Sample Input 2
4 3
1 2 3
1 1 1
1 1 0
1 0 1
0 1 1
Sample Output 2
-1
Explanation for Sample 2
Purchasing only the first stamp type satisfies the condition for the second, third, and fourth friend, but it does not satisfy the condition for the first friend. There is no collection of stamp types which satisfies the condition for all four friends.
Comments