Problems
Buns eating
Buns eating
Kratos and Atreus decided to eat buns. To diversify the process, Kratos prepared $2k$ buns and offered to arrange a speed-eating competition.
Both Kratos and Atreus will eat $k$ buns. It all ended as fast as it started. Freya secretly watched this contest and noticed several features:
\begin{itemize}
\item Both contestants ate exactly $k$ buns.
\item In one action, Kratos or Atreus ate either one or two buns.
\item Each time one of them took an action, he recorded how many buns he ate.
\end{itemize}
After Kratos and Atreus left, Freya found their “protocol." Unfortunately, for each action, it is recorded how many buns were eaten, but it was not recorded who exactly ate them.
Freya remembers that at some point in the competition, Kratos looked like an unconditional leader, since he ate buns much more than Atreus. She asks you, according to this protocol, to determine what the largest gap Kratos could have during the competition.
\InputFile
The first line contains two integers $n$ and $k~(2 \le n \le 10^5, 1 \le k \le n)$ --- the number of entries in the protocol and the number of buns eaten by each of the participants.
The second line contains $n$ integers $a_i~(1 \le a_i \le 2)$ --- the protocol data. It is guaranteed that the protocol is correct: you can divide $a_i$ into two sets so that the sum of the numbers in both sets is $k$.
\OutputFile
Print a single integer --- the largest advantage of Kratos during the match.
Input example #1
3 2 1 2 1
Output example #1
1