Time limit
2s
Memory limit
128 MB
Several people want to buy one item, and each participant submits the price they are willing to pay. In a usual auction, the item is sold to the person who offered the highest price. In some auction variants, however, lower prices are preferred.
If the lowest price always won, everyone could simply offer the minimum amount. To avoid that, prices offered by many people are treated as less competitive. The winner is chosen by the following rules.
First, among all offered prices, find the price that was offered by the fewest people. If there are several such prices, choose the lowest one. Finally, among the people who offered the chosen price, the person who submitted that price earliest wins the item.
Given each participant's name and offered price in submission order, determine the winner's name and winning price.
The first line contains two integers U and N. U is the maximum allowed price, and N is the number of bids.
1 ≤ U ≤ 10,0001 ≤ N ≤ 100,000Each of the next N lines contains a name S and a price P, in the order the bids were submitted.
S consists of uppercase and lowercase English letters with no spaces and has length at most 10.1 ≤ P ≤ UP is an integer.Print the winner's name and the winning price on one line, separated by a space.