{"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 The $h$-index of an author is the largest $h$ where he has at least $h$ papers with citations not less than $h$. \n \u003cbr\u003e \n \u003cbr\u003eBobo has published $n$ papers with citations $a_1, a_2, \\dots, a_n$ respectively. \n \u003cbr\u003eOne day, he raises $q$ questions. The $i$-th question is described by two integers $l_i$ and $r_i$, asking the $h$-index of Bobo if has *only* published papers with citations $a_{l_i}, a_{l_i + 1}, \\dots, a_{r_i}$. \n \u003cbr\u003e \n\u003c/div\u003e\n给n个数,q次询问,每次询问给出一个区间[l,r],要你求出最大的h,使得在[l,r]这个区间内满足,有h个数的值大于等于h。"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of several test cases and is terminated by end-of-file. \n\u003cbr\u003e \n\u003cbr\u003eThe first line of each test case contains two integers $n$ and $q$. \n\u003cbr\u003eThe second line contains $n$ integers $a_1, a_2, \\dots, a_n$. \n\u003cbr\u003eThe $i$-th of last $q$ lines contains two integers $l_i$ and $r_i$. \n\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each question, print an integer which denotes the answer. \n\u003cbr\u003e \n\u003cbr\u003e## Constraint \n\u003cbr\u003e \n\u003cbr\u003e* $1 \\leq n, q \\leq 10^5$ \n\u003cbr\u003e* $1 \\leq a_i \\leq n$ \n\u003cbr\u003e* $1 \\leq l_i \\leq r_i \\leq n$ \n\u003cbr\u003e* The sum of $n$ does not exceed $250,000$. \n\u003cbr\u003e* The sum of $q$ does not exceed $250,000$. \n\u003cbr\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e5 3\n1 5 3 2 1\n1 3\n2 4\n1 5\n5 1\n1 2 3 4 5\n1 5\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e2\n2\n2\n3\u003c/pre\u003e"}}]}