Playing cards is a nice way to spend time. However, when prize money is involved, sometimes players get involved in a more professional way and try to learn as much as possible about the game. One particular concern is finding out the minimum number of cards needed to obtain a hand of a determined rank, if possible, given the card ranking. You have been asked to write a computer program to help out.
For example, considering aces rank 25 points, figures (kings, queens and jacks) rank 10 points and numbered cards rank 1 point, the minimum number of cards to obtain a 30 point hand is 3 (three figures). Notice that in this case it is possible to obtain hands of any rank, but if numbered cards ranked 5 then it would not be possible to obtain a 12 point ranked hand.
Given the desired hand rank and a card ranking, your program must determine the minimum number of cards needed to obtain, if possible, the desired rank, considering unlimited decks.
The first line includes two integers C and H, which specify the number of card types and the desired hand rank respectively. The following C lines include a string T and an integer R, separated by a single white space, which specify the card type and the card rank, respectively.
|•||1 ≤ C ≤ 56||Number of card types|
|•||1 ≤ H ≤ 1000000||Hand rank desired|
|•||1 ≤ R ≤ 100||Card rank|
The output consists in a single line containing the minimum number of cards needed to obtain a hand of the desired rank, if possible, or NO otherwise.
3 30 Ace 25 Figure 10 Number 1
3 12 Ace 25 Figure 10 Number 5