{"raw_statement":[{"iden":"problem statement","content":"You are given a length-$N$ sequence of non-negative integers.  \nWhen $B$ is a sequence obtained by choosing $K$ elements from $A$ and concatenating them without changing the order, find the maximum possible value of $MEX(B)$.\nHere, for a sequence $X$, we define $MEX(X)$ as the unique non-negative integer $m$ that satisfies the following conditions:\n\n*   Every integer $i$ such that $0 \\le i < m$ is contained in $X$.\n*   $m$ is not contained in $X$."},{"iden":"constraints","content":"*   All values in the input are integers.\n*   $1 \\le K \\le N \\le 3 \\times 10^5$\n*   $0 \\le A_i \\le 10^9$"},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $K$\n$A_1$ $A_2$ $\\dots$ $A_N$"},{"iden":"sample input 1","content":"7 3\n2 0 2 3 2 1 9"},{"iden":"sample output 1","content":"3\n\nIn this input, $A=(2,0,2,3,2,1,9)$, and you obtain the sequence $B$ by picking $K=3$ elements. For example,\n\n*   If the $1$\\-st, $2$\\-nd, and $3$\\-rd elements are chosen, $MEX(B)=MEX(2,0,2)=1$.\n*   If the $3$\\-rd, $4$\\-th, and $6$\\-th elements are chosen, $MEX(B)=MEX(2,3,1)=0$.\n*   If the $2$\\-nd, $6$\\-th, and $7$\\-th elements are chosen, $MEX(B)=MEX(0,1,9)=2$.\n*   If the $2$\\-nd, $3$\\-rd, and $6$\\-th elements are chosen, $MEX(B)=MEX(0,2,1)=3$.\n\nThe maximum possible $MEX$ is $3$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}