In a factory where blank CD discs are produced, they are stacked into a "pyramid" of discs, ideally with their working side facing down. However, sometimes they may be incorrectly stacked, with some discs facing up and some facing down. The factory has a special machine that can remove any number of discs from the top of the stack, flip them (so the bottom of the removed pile becomes the top), and place them back without changing the internal order of the flipped pile. The task is to determine the minimum number of such operations required to make all discs in the pyramid stacked correctly, i.e., with their working side facing down.
The input consists of the number of discs (1 \leq N \leq 100\,000), followed by integers ( if the working side of the disc is down, if up), starting from the top disc of the pyramid. All integers are separated by spaces.
Output a single number — the minimum number of operations required. If it is impossible to put the pyramid in the correct order, output -1.
Example 1