题目描述
Problem Description
A JOI official works at a toy store. Today, they have to organize the plush toy corner in the store.
The plush toy corner's shelf has $ N $ plush toys arranged from left to right in a single row. The shelf is divided into $ N $ compartments by partitions, with one plush toy in each compartment. The toy store sells a total of $ M $ types of plush toys, numbered from $ 1 $ to $ M $. The $ N $ plush toys on the shelf are each one of these $ M $ types. Furthermore, it is guaranteed that at least one plush toy of each type exists.
To improve the appearance, they want to rearrange the plush toys so that all plush toys of the same type are consecutive on the shelf. They decided to rearrange the plush toys in the following way:
- Select some of the $ N $ plush toys and remove them from the shelf. The positions of the plush toys that are not removed will not be changed.
- Place the removed plush toys back into the empty compartments on the shelf in any order.
After rearranging, all plush toys of the same type must be consecutive on the shelf. Write a program to determine the minimum number of plush toys that need to be removed for this rearrangement.
Input Format
The input consists of $ 1 + N $ lines.
The first line contains two integers $ N, M $ ($1 \leq N \leq 100,000$, $1 \leq M \leq 20$), indicating that there are $ N $ plush toys and $ M $ types of plush toys.
The following $ N $ lines each contain an integer between $ 1 $ and $ M $. The integer on the $ i $-th line ($1 \leq i \leq N$) represents the type of the plush toy in the $ i $-th compartment from the left on the shelf. It is guaranteed that there is at least one plush toy of each type.
Output Format
Output the minimum number of plush toys that need to be removed for the rearrangement on a single line.
Sample Input and Output
Sample Input #1
7 2
1
2
2
2
1
2
1
Sample Output #1
2
Sample Input #2
12 4
1
3
2
4
2
1
2
3
1
1
3
4
Sample Output #2
7
Notes/Hints
Sample Explanation 1
In the first input example, the types of plush toys initially placed from left to right are $ 1, 2, 2, 2, 1, 2, 1 $. To minimize the number of plush toys removed, take out the plush toys in the 1st and 6th positions, and place a type $ 2 $ plush toy in the 1st position and a type $ 1 $ plush toy in the 6th position. This results in removing 2 plush toys.
Sample Explanation 2
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分