{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n Dandelion\u0027s 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. \n \u003cbr\u003e The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a\u0027s reward should more than b\u0027s.Dandelion\u0027s uncle wants to fulfill all the demands, of course ,he wants to use the least money.Every work\u0027s reward will be at least 888 , because it\u0027s a lucky number. \n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"One line with two integers n and m ,stands for the number of works and the number of demands .(n\u0026lt;\u003d10000,m\u0026lt;\u003d20000) \n\u003cbr\u003ethen m lines ,each line contains two integers a and b ,stands for a\u0027s reward should be more than b\u0027s."}},{"title":"Output","value":{"format":"HTML","content":"For every case ,print the least money dandelion \u0027s uncle needs to distribute .If it\u0027s impossible to fulfill all the works\u0027 demands ,print -1."}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e2 1\n1 2\n2 2\n1 2\n2 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e1777\n-1\u003c/pre\u003e"}}]}