{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eDo you think that sorting is easy? This is not the case when you\u0027re running out of time.\u003c/p\u003e\n\n\u003cp\u003eUnexpected weird things often happen in our life. For example, now you have array \u003cstrong\u003eA\u003c/strong\u003e and you need to sort it in non-decreasing order. The problem is that you don\u0027t really have time to do that.\u003c/p\u003e\n\n\u003cp\u003eFortunately, your friend is very good at sorting arrays, so you decided to ask for his help. You believe that your friend\u0027s special abilities are due to his very conceptual approach. In one second he takes an element out of the array and places it either at the beginning or the end of the array.\u003c/p\u003e\n\n\u003cp\u003eFor example, if the array is \u003cstrong\u003e4 2 5 6 1 3\u003c/strong\u003e, then taking out \u003cstrong\u003e5\u003c/strong\u003e and placing it at the beginning would yield \u003cstrong\u003e5 4 2 6 1 3\u003c/strong\u003e, while taking out \u003cstrong\u003e2\u003c/strong\u003e and placing it at the end would yield \u003cstrong\u003e4 5 6 1 3 2\u003c/strong\u003e.\u003c/p\u003e\n\n\u003cp\u003eOf course, your friend does everything as fast as possible, because he doesn\u0027t want to waste his time. The only thing you want to know is how much time you have for doing other useful things while your array is being sorted.\u003c/p\u003e\n\n\u003cp\u003e\u003ch2\u003eInput\u003c/h2\u003e\u003c/p\u003e\n\n\u003cp\u003eThe first line contains \u003cstrong\u003eN\u003c/strong\u003e (\u003cstrong\u003e1\u003c/strong\u003e ≤ \u003cstrong\u003eN\u003c/strong\u003e ≤ \u003cstrong\u003e3\u003c/strong\u003e∙\u003cstrong\u003e10^5\u003c/strong\u003e) - the number of elements in \u003cstrong\u003eA\u003c/strong\u003e. The second line contains \u003cstrong\u003eN\u003c/strong\u003e integer numbers \u003cstrong\u003eA_i\u003c/strong\u003e (\u003cstrong\u003e1\u003c/strong\u003e ≤ \u003cstrong\u003eA_i\u003c/strong\u003e ≤ \u003cstrong\u003e10^6\u003c/strong\u003e)\u003c/p\u003e\n\n\u003cp\u003e\u003ch2\u003eOutput\u003c/h2\u003e\u003c/p\u003e\n\n\u003cp\u003ePrint the sought minimum time needed for your friend to sort \u003cstrong\u003eA\u003c/strong\u003e, in seconds.\u003c/p\u003e\n\n"}},{"title":"Example","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\u003e5\n2 5 1 3 3\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"}}]}