CD
In a factory that manufactures blank CDs, the CDs are stacked in "pyramids," one on top of the other, with a total of N CDs. Ideally, each CD should have its working side facing down. However, sometimes CDs are incorrectly stacked, with some facing up. The factory has a special machine that can remove any number of CDs from the top of the stack, flip them, and then place them back on top, reversing their order. The goal is to determine the minimum number of such operations needed to ensure all CDs in the stack have their working side facing down.
Input
The input consists of the number of CDs, N (1 ≤ N ≤ 100000), followed by N integers. Each integer is either 1 (indicating the CD is facing down) or 0 (indicating the CD is facing up), listed from the top of the stack to the bottom. The integers are separated by spaces.
Output
The output should be a single integer representing the minimum number of operations required to correctly arrange all CDs with their working side down. If it is impossible to achieve this arrangement, output -1.