2418: Wages

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

A Company Master ran into a problem recently and need your help.
With the annual summer vacation,he wants to distribute rewards to his workers.
But some workers have demands of the distributing of rewards,they think they are work hader than someone,so that their wages should more than them.
ACM is a good guy,so he wants to fulfull all the demands,of course,he must use the least money.
Everyone's wages will be at least 2333,because it's BB.

输入格式

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

输出格式

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

输入样例 复制

2 1
1 2
2 2
1 2
2 1

输出样例 复制

4667
-1

分类标签