Have you heard about Splendor's board game? We will adapt the process of this game.
There are five colors of chips and gems in this game: white, blue, red, green and black. You start with zero chip.
There will be $N$ gem cards and $M$ pirates,Each gem card has three attributes,score,gem type,in exchange for the chips needed.
In each turn,you can exchange the corresponding chip for one card,then you will gain the score of this card and the gem on this card.
(Once you have this card,you can't get the same card next time.)
But noticed: there can be no score in a gem card.
When the pirate observes that you have the type and number of gems he wants, the pirate will automatically come to you and you will receive the pirate's score.(Means that you will get bonus scores.)
In each turn, you can do one of the three things:
1. Obtain any three different colored chips from the stack.
2. Obtain any two chips of the same color from the stack.
3. Exchange your chips for gems.
Now, you have known all the gems and pirates.Your goal is to reach the minimum $goal$ score as soon as possible. How many turns does it take?(If it can't reach the minimum goal,you should output $-1$.)