Correcting Cheeseburgers
Cheeseburgers are serious business. They are the most delicious food on earth, but there is a lot of room for error when making a cheeseburger. Even otherwise capable cooks often mess up the order of the assembled ingredients.
The only correct order of ingredients between the buns is, of course, as following from top to bottom:
Ketchup Mustard
Beef Tomato
Pickles
Red Onions
Cheddar Cheese
Garlic
Salt Pepper
Beef Patty, medium grilled
Corn Salad
Mayonnaise
Any deviation from this order is completely unacceptable. Therefore it is sometimes necessary to reassemble a cheeseburger.
Space on an average plate and social norms are rather restrictive when it comes to operating on a cheeseburger. The only feasible operation is the bit-shuffle (burger-ineptly-transformed). The bit-shuffle separates the entire burger into four parts of contiguous ingredients and and arranges them in the new order . The size of each of the four parts is selectable and may be zero.
Since the burger cools rapidly we are interested in the minimum required bit-shuffles to arrive at an acceptable burger.
Each given cheeseburger consists of unique ingredients labeled from to . The correct order is always the natural order .
Input
First line contains the number of ingredients used. Second line contains integers describing the order of the ingredients of the given cheeseburger. The ingredients are numbered from to .
Output
Output the minimum number of bit-shuffles to correct the given cheeseburger.
Examples
Note
Illustration of the first sample input:
Illustration of the second sample input: