Matches

No attempts yetTime limit1sMemory limit512 MB

Problem

Bajtek is playing with matches. Each match has a head on one end, coated with a substance that makes it easy to ignite. Bajtek laid the matches in a straight line, side by side, so that every end of a match touches an end of another match, except for the two outermost matches, each of which touches another match at only one end.

An example arrangement of the matches.

Bajtek wants to light the leftmost match so that all of the matches burn. He lights the first match with a lighter, so he can always ignite it no matter which way it faces. Between two neighboring matches, however, the fire spreads only if at least one of the two matches has its head at the point where they touch. Find the minimum number of matches that must be flipped so that, after the first match is lit, every match burns.

Input

The first line contains a single integer nn (1n10000001 \le n \le 1\,000\,000), the number of matches. The second line describes their orientation with nn integers x1,x2,,xnx_1, x_2, \dots, x_n, where xix_i is the orientation of the ii-th match: 00 if its head is on the left and 11 if its head is on the right.

Output

Print a single integer: the minimum number of matches that must be flipped.

Hint