cswork / OAOpen practice workspace

AdobeOA #1

Freelancer Bidding (Minimum Customer Cost)

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Choose one quote for each project and find the minimum total price to complete all projects; if any project has no quote, return −1. Quotes do not constrain one another.

Input

The first line contains the number of projects p and the number of quotes n, followed by n lines, each with a project ID and a quote. The original full bounds are 1≤p,n<500000, and project IDs are 0..p−1 as in the original example. The original range of quote values is missing; this site adds −10^9..10^9. Output the exact integer.

Output

Output a single integer answer.

Example 1

Input:

3 4
2 8
0 7
1 6
2 9

Output:

21

Example 2

Input:

4 3
2 8
0 7
1 6

Output:

-1

Example 3

Input:

1 2
0 0
0 -2

Output:

-2

Example notes

The outputs of the three public examples are, in order: 21; -1; -2. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…