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