{"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\u003eConsider an array $$$A$$$ and a set $$$B$$$ of integers such that \u003cspan class\u003d\"tex-font-style-bf\"\u003eall numbers in $$$A$$$ and $$$B$$$ are distinct\u003c/span\u003e. Your task is to turn $$$A$$$ into a sorted array. To do this you can take any number from $$$B$$$ and replace any element of $$$A$$$ with it. You can perform this operation any number of times, but each element of $$$B$$$ can be used at most once.\u003c/p\u003e\u003cp\u003eDetermine the minimum number of operations needed to turn $$$A$$$ into a sorted array, or determine that it is impossible.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains two integers $$$N$$$ and $$$M$$$ ($$$1 \\le N, M \\le 5 \\cdot 10^5$$$)\u0026nbsp;— the sizes of $$$A$$$ and $$$B$$$ respectively.\u003c/p\u003e\u003cp\u003eThe second line contains $$$N$$$ integers $$$A_1, A_2, \\ldots, A_N$$$.\u003c/p\u003e\u003cp\u003eThe third line contains $$$M$$$ integers $$$B_1, B_2, \\ldots, B_M$$$.\u003c/p\u003e\u003cp\u003eAll the $$$(N + M)$$$ elements are distinct, positive and do not exceed $$$10^9$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eIf it is impossible to turn $$$A$$$ into a sorted array, print $$$-1$$$. Otherwise, print the minimum number of operations needed.\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\u003e4 1\n2 6 13 10\n5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\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\u003e4 2\n2 6 13 10\n5 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\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\u003e4 3\n2 6 13 10\n5 4 19\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":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn all three examples, the issue is that $$$13 \u0026gt; 10$$$, so we have to change at least one of them.\u003c/p\u003e\u003cp\u003eIn the first one, we can decrease $$$13$$$ by replacing it with $$$5$$$, but it breaks the other side, so there is no solution.\u003c/p\u003e\u003cp\u003eIn the second one, we also have $$$4$$$, which we can use to fix the broken side. It is impossible to do with less than $$$2$$$ operations.\u003c/p\u003e\u003cp\u003eIn the third example we can finally increase the last element, thus fixing $$$A$$$ in 1 operation.\u003c/p\u003e"}}]}