Meal deals

Edgar has become fond of the “meal deals” of England. For 3.5 pounds he
can eat one first, one second, one third, …, and one n-th dish. Edgar
wants to eat as many calories as possible, and he knows, for every dish
of the deal, its type (between 1 and n) and its number of calories. Take
into account that he can eat (at most) one dish of each type.

Input

Input consists of several cases, with only natural numbers. Every case
begins with the number of types of dishes n and the number of different
dishes d, followed by d pairs t_(i) c_(i) with the type and the number
of calories of each dish. There is at least one dish for each type.
Assume 1 ≤ n ≤ 10⁴, n ≤ d ≤ 10⁵, 1 ≤ t_(i) ≤ n, and 1 ≤ c_(i) ≤ 10⁵.

Output

For each meal deal, print the maximum number of calories that Edgar can
eat.

Problem information

Author: Edgar Moreno

Generation: 2026-01-25T11:06:59.893Z

© Jutge.org, 2006–2026.
https://jutge.org
