After many years of work, the foolish old man has finally finished levelling the mountains around his home. However, his descendants soon realise that a completely flat landscape is rather boring, so they decide to build a new mountain instead.

The new landscape is represented by an array $A$ of $N$ integers, where $A_i$ is the height of the $i$-th position and $N$ is odd. It forms a strict mountain: there is exactly one peak at position $P$, and $$ A_1<A_2<\cdots<A_P>A_{P+1}>\cdots>A_N. $$

This time, instead of flattening the mountain, they want to adjust its heights while keeping its overall shape. In one day, they may choose a position $i$ and increase its height $A_i$ by $1$.

After all adjustments, let the resulting landscape be $B$. It must still be a strict mountain with its peak at the same position $P$. In addition, the median* height of $B$ must be exactly $K$, and exactly one position must have height $K$. Heights at non-adjacent positions are allowed to be equal.

* The median of an array of odd length is the middle value after sorting the array in non-decreasing order.

Find the minimum number of days required to achieve this. If it is impossible, output -1.

Input

The first line contains two integers $N$ and $K$.

The second line contains $N$ integers $A_1,A_2,\ldots,A_N$.

Output

Output one integer, the minimum total cost required.

If it is impossible, output -1.

Constraints

For all cases: $3\le N\le2\times10^5$, $N$ is odd, $1\le A_i,K\le10^9$
$A$ forms a strict mountain.
Subtask 1 (13%): $|A_i - A_{i+1}| = 1$ for all $1\le i\le N$
Subtask 2 (17%): $K>\max A_i$ for all $1\le i\le N$, and $P=\frac{N+1}{2}$
Subtask 3 (19%): $K>\max A_i$ for all $1\le i\le N$
Subtask 4 (23%): $N\le3000$
Subtask 5 (28%): No additional constraints

Sample Test Cases

Input Output
5 5
1 4 7 5 2
2

One optimal resulting landscape is $[1,5,7,6,2]$. Its median is $5$, only the second position has height $5$, and the total cost is $2$.

7 6
1 10 9 7 4 3 2
2

One optimal resulting landscape is $[1,10,9,7,6,3,2]$. Only the fifth position is changed, at a cost of $2$.

Click to copy.

Scoring: Per Subtask
Authored by s19x17
Appeared in 2026 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆