{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou\u0027re given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Nodes are numbered from $$$1$$$ to $$$n$$$.\u003c/p\u003e\u003cp\u003eThe graph is considered \u003cspan class\u003d\"tex-font-style-it\"\u003eharmonious\u003c/span\u003e if and only if the following property holds:\u003c/p\u003e\u003cul\u003e \u003cli\u003e For every triple of integers $$$(l, m, r)$$$ such that $$$1 \\le l \u0026lt; m \u0026lt; r \\le n$$$, if there exists a \u003cspan class\u003d\"tex-font-style-bf\"\u003epath\u003c/span\u003e going from node $$$l$$$ to node $$$r$$$, then there exists a \u003cspan class\u003d\"tex-font-style-bf\"\u003epath\u003c/span\u003e going from node $$$l$$$ to node $$$m$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIn other words, in a harmonious graph, if from a node $$$l$$$ we can reach a node $$$r$$$ through edges ($$$l \u0026lt; r$$$), then we should able to reach nodes $$$(l+1), (l+2), \\ldots, (r-1)$$$ too.\u003c/p\u003e\u003cp\u003eWhat is the minimum number of edges we need to add to make the graph harmonious? \u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \\le n \\le 200\\ 000$$$ and $$$1 \\le m \\le 200\\ 000$$$).\u003c/p\u003e\u003cp\u003eThe $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \\le u_i, v_i \\le n$$$, $$$u_i \\neq v_i$$$), that mean that there\u0027s an edge between nodes $$$u$$$ and $$$v$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint the minimum number of edges we have to add to the graph to make it harmonious.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e200000 3\n7 9\n9 8\n4 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example, the given graph is not harmonious (for instance, $$$1 \u0026lt; 6 \u0026lt; 7$$$, node $$$1$$$ can reach node $$$7$$$ through the path $$$1 \\rightarrow 2 \\rightarrow 7$$$, but node $$$1$$$ can\u0027t reach node $$$6$$$). However adding the edge $$$(2, 4)$$$ is sufficient to make it harmonious.\u003c/p\u003e\u003cp\u003eIn the second example, the given graph is already harmonious.\u003c/p\u003e"}}]}