Correcting Cheeseburgers#7946

Correcting Cheeseburgers

5 seconds
256 megabytes
Very hard

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:

  1. Ketchup Mustard

  2. Beef Tomato

  3. Pickles

  4. Red Onions

  5. Cheddar Cheese

  6. Garlic

  7. Salt Pepper

  8. Beef Patty, medium grilled

  9. Corn Salad

  10. 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 a, b, c 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 n~(1 \le n \le 10) 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

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

Illustration of the first sample input:

Illustration of the second sample input: