Choose Colors
Miss M not only enjoys inventing interesting legends for programming problems but also loves painting, especially using harmonious color combinations, such as complementary colors from the color wheel. However, this time she decided to choose colors for her painting differently.
Miss M took color wheels (you can look at the note section to see what a color wheel is), each with different shades consisting of colors, and has already selected one initial color on each wheel, marking it as used. Then, she will choose each subsequent color using the following algorithm:
Find the longest sequence among all the color wheels of unmarked colors; if there are several, choose any.
If the length of such a sequence is odd, take the color exactly in the middle and mark it as used.
If the length of such a sequence is even, take one of the two middle colors and mark it as used.
Miss M wants to choose more colors, and she is also interested in what the maximum length of the sequence of unmarked colors will be before she selects the -th color.
Input
The first line contains two integers and (, ) — the number of color wheels and the number of colors Miss M wants to take additionally (i.e., not counting the first marked colors on each wheel).
The second line contains integers ().
It is guaranteed that is no more than the sum of all .
Output
Print a single integer — the maximum length of the sequence of unmarked colors before Miss M selects the -th color.
Examples
Note
Explanation for the second example: We are given one color wheel containing colors. Miss M has already chosen one color from the wheel (marked as number in the picture). Now she wants to choose more colors. Therefore, the sequence of her actions is as follows:
The maximum length of the sequence of unmarked colors is . Therefore, we choose the color that will be in the middle and mark it with the number .
Now we have sequences of and unmarked colors; we choose any and in the middle of the sequence, we select a color and mark it with the number .
Among the sequences — , , and we choose — this is the maximum length of the sequence of unmarked colors before Miss M selects the -th color.
The color wheel from the second example in the problem statement.
Scoring
If your solution works correctly for and , it will score at least points.
If your solution works correctly for and , it will score at least points.
If your solution works correctly for , it will score at least points.