Time limit
2s
Memory limit
128 MB
Jadu likes plums, so there are two plum trees at home. Jadu is too short to pick fruit directly and can eat a plum only if standing under the tree at the instant it falls. Once a plum hits the ground, it is too crushed to eat.
Each second, exactly one of the two trees drops one plum. Jadu can move from one tree to the other in much less than one second, but wants to move at most W times.
For T seconds, the falling tree for each second is given. Compute the maximum number of plums Jadu can catch. Jadu starts under tree 1. T is between 1 and 1,000 inclusive, and W is between 1 and 30 inclusive.
The first line contains two integers T and W. Each of the next T lines contains the number of the tree, either 1 or 2, from which a plum falls at that second.
Print one integer: the maximum number of plums Jadu can catch.