{"raw_statement":[{"iden":"problem statement","content":"Takahashi is going to read a manga series \"Snuke-kun\" in $10^9$ volumes.  \nInitially, Takahashi has $N$ books of this series. The $i$\\-th book is Volume $a_i$.\nTakahashi may repeat the following operation any number of (possibly zero) times **only before he begins to read**:\n\n*   Do nothing if he has $1$ or less books; otherwise, sell two of the books he has and buy one book of any volume instead.\n\nThen, Takahashi reads Volume $1$, Volume $2$, Volume $3$, $\\ldots$, in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).\nFind the latest volume of the series that he can read up to. If he cannot read any, let the answer be $0$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 3 \\times 10^5$\n*   $1 \\leq a_i \\leq 10^9$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$a_1$ $\\ldots$ $a_N$"},{"iden":"sample input 1","content":"6\n1 2 4 6 7 271"},{"iden":"sample output 1","content":"4\n\nBefore he begins to read the series, he may do the following operation: \"sell books of Volumes $7$ and $271$ and buy one book of Volume $3$ instead.\" Then, he has one book each of Volumes $1$, $2$, $3$, $4$, and $6$.  \nIf he then begins to read the series, he reads Volumes $1$, $2$, $3$, and $4$, then tries to read Volume $5$. However, he does not have one, so he stops reading at this point.  \nRegardless of the choices in the operation, he cannot read Volume $5$, so the answer is $4$."},{"iden":"sample input 2","content":"10\n1 1 1 1 1 1 1 1 1 1"},{"iden":"sample output 2","content":"5\n\nTakahashi may have multiple books of the same volume.  \nFor this input, if he performs the following $4$ operations before he begins to read the series, he can read up to Volume $5$, which is the maximum:\n\n*   Sell two books of Volume $1$ and buy a book of Volume $2$ instead.\n*   Sell two books of Volume $1$ and buy a book of Volume $3$ instead.\n*   Sell two books of Volume $1$ and buy a book of Volume $4$ instead.\n*   Sell two books of Volume $1$ and buy a book of Volume $5$ instead."},{"iden":"sample input 3","content":"1\n5"},{"iden":"sample output 3","content":"0\n\nTakahashi cannot read Volume $1$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}