Bob lives in a chaotic country with

cities in a row, numbered from

to

. These cities are owned by different lords, and the

-th cities currently belongs to the

-th lord. To simply problems, we assume there are

lords in the country, and they are also numbered from

to

. Some lords may take control of multiple cities, while some new-born lords have not got any cities yet.
Obviously, the greedy lords are not satisfied with the number of territories they have, so the country is constantly at war. Bob wants to change that, by making all the cities belong to the same lord!
Bob can perform some magical operations to support his grand plan. With the help of each magic, Bob can do the following:
- Choose some cities with consecutive indices such that they belong to the same lord, and assign them to any other lord.
As magics are really tiring, Bob wants to know the minimum number of such operations he needs to use to make all the cities belong to one lord.
The following picture shows an example where

. Different shapes are used to represent cities belonging to different lords. As shown in the picture, the minimum number of magic operations used is 2.