Problem G. Reward

时间限制 1000 ms   内存限制 32 MB

Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.
The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
 

输入数据

One line with two integers n and m ,stands for the number of works and the number of demands .(n<=10000,m<=20000)
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
 

输出数据

For every case ,print the least money dandelion 's uncle needs to distribute .If it's impossible to fulfill all the works' demands ,print -1.
 

样例输入

复制
2 1
1 2
2 2
1 2
2 1

样例输出

复制
1777
-1

提交

请先 登录

Announcement

请大家写题的时候多注意一下题目的细节,例如多种方案时的输出要求。 这些题网上都可以查到题解,希望大家先尽量自己完成,实在想不出来的最好先和同学交流之后再去看题解。

© 2025 FAQs Contact About