"Pawns" is a game played on a board of length $N$ and width $1$. The board is divided into $N$ unit squares, numbered $1, 2, \ldots, N$ from left to right. At any moment each square is either empty or occupied by a single pawn. Every pawn is either white or black. You are given the initial position of every pawn.
Pawns move according to the following rules:
A pawn must always remain on the board after moving. Note that whenever a pawn can move, exactly one of its two moves is possible, because the two conditions are mutually exclusive.
The game is complete when all white pawns occupy the front (leftmost) squares and all black pawns occupy the back (rightmost) squares, with no gaps: the white pawns fill positions $1, 2, \ldots$ contiguously, and the black pawns fill positions $N, N-1, \ldots$ contiguously.
Given the initial positions, find the minimum number of moves needed to complete the game. It is guaranteed that the game can be completed in a finite number of moves.
The first line contains the integer $N$, the length of the board. The second line contains $N$ integers from the set ${0, 1, 2}$ separated by single spaces: $0$ is an empty square, $1$ is a white pawn and $2$ is a black pawn. The $i$-th number describes the $i$-th square of the board.
Output a single integer: the minimum number of moves needed to complete the game.
For the sample board 2 0 0 2 1, the initial configuration and the configuration after each of the $5$ moves are illustrated below:
