Sequential Nim

In Sequential Nim, players must take stones from piles in order. They start with pile 0, and a move consists of removing any positive number of stones from the current pile. When a pile becomes empty, play moves to the next non-empty pile to the right. The player who takes the last stone wins. Determine which player wins: return 1 if the first player wins, 2 if the second player wins.

The piles are fixed in an order and a player may only take from the leftmost non-empty pile, so play proceeds left to right instead of allowing a free choice of pile. The game ends when the last stone is taken, and the player who takes it wins.

Piles of size one force the move: the only legal option is to take the single stone and pass the turn. The first pile with two or more stones is where a player gains control, because that player can take the whole pile or leave one stone and force the opponent to open the next pile. Count the leading piles that contain exactly one stone. If every pile is a single stone, the parity of that count decides the winner. Otherwise the player to move at the first large pile controls the remainder of the game, and the parity of the leading ones decides who that player is.

Examples
Input: [1,1]
Output: 2
Hints

Sequential Nim

In Sequential Nim, players must take stones from piles **in order**. They start with pile 0, and a move consists of removing any positive number of stones from the current pile. When a pile becomes empty, play moves to the next non-empty pile to the right. The player who takes the last stone wins. Determine which player wins: return 1 if the first player wins, 2 if the second player wins.