#t121. 小杨的智慧购物

小杨的智慧购物

Xiaoyang's Smart Shopping

Problem Description

Xiaoyang's class is holding an eco-friendly handcraft exhibition, and the teacher asks Xiaoyang to go to the stationery store to buy MM different kinds of stationery (for example: pencils, erasers, rulers, etc.).

The store has NN items in total, and each item has a type id (from 11 to MM) and a price.

Xiaoyang's budget is limited, so he came up with a clever idea: for each kind of stationery, he only buys the cheapest one (if several items of the same kind share the lowest price, he buys only one of them). Please help Xiaoyang compute how much he needs to spend in total to buy all MM kinds of stationery.

Input Format

The first line contains two positive integers M,NM, N, the number of kinds of stationery and the total number of items.

The following NN lines each contain two positive integers KiK_i and PiP_i, representing the type id and the price of the ii-th item. The data guarantees that each kind has at least one item available to buy.

Output Format

Output one line: the total price of the stationery purchased.

Sample Input

2 5
1 1
1 2
1 1
2 3
2 10

Sample Output

4

Sample Explanation

The item list is as follows:

  • Item 1: type 11, price 11
  • Item 2: type 11, price 22
  • Item 3: type 11, price 11
  • Item 4: type 22, price 33
  • Item 5: type 22, price 1010

Xiaoyang's selection process: for type 11, there are three items priced 1,2,11, 2, 1, the cheapest of which is 11; for type 22, there are two items priced 3,103, 10, the cheapest of which is 33.

Total price: Xiaoyang spends 1+3=41 + 3 = 4 in total for these two kinds of stationery.

Constraints

For all test cases, 1≤M≤N≤1051 \leq M \leq N \leq 10^5, 1≤Ki≤M1 \leq K_i \leq M, 1≤Pi≤1031 \leq P_i \leq 10^3.