the prince and the salty fish Time limit:1000/1000ms (java/others) Memory limit:120000/120000kb (java/others) Submit Status
One day, meow haha village, the pillars in their own room, face Magic mirror
"Magic Mirror, Magic Mirror, what is the most powerful martial arts in the world." "
In a moment, a thunder fell, the pillars of the front unexpectedly came out of an ancient black books, and the name of the book is "Salted Fish Martial" "" Salty fish Martial "!
Open a look, the first page of the book impressively read: "Practice to large into a variable body of salted fish King, control thunder and lightning." Practice to big into variable body salted fish king, control thunder and lightning. “
See this sentence, the prince immediately decided to cultivate salted fish martial.
Since it is the martial, it is not so good practice, so the column master decided to well plan his own cultivation process.
The column I have nn point mood value, and salted fish martial arts have mm a moves, for each moves, the column ye must consume Titi point mood value to master, at the same time the column ye will get the cultivation value of Vivi
So what is the maximum amount of cultivation that the Lord can get? Input
The first line of two integers nn,mm, respectively, indicating the mood points of the Lord and the number of moves of salted fish
Next mm line, 2 per line