#P11931. Notebook Moves Minimization

    ID: 14038 Type: Default 1000ms 256MiB

Notebook Moves Minimization

Notebook Moves Minimization

You are given \(n\) pieces of clothing that must be stacked in order. There are \(k\) types of clothing and the \(j\)th type of clothing must be placed on pile \(j\). The \(i\)th clothing item is of type \(a_i\). You always carry a math notebook with you and you want to keep it clean, so you initially place it on one of the piles. However, clothes cannot be stacked on top of the notebook. Therefore, if you want to place a clothing item on the same pile where the notebook is currently located, you must move the notebook to another pile (you can choose any other pile).

You can choose the initial pile for the notebook arbitrarily and you may move it arbitrarily (subject to the rule that you cannot stack on the pile holding the notebook).

Determine the minimum number of moves required for the notebook if an optimal strategy is used.

Note: When a clothing item of type \(x\) appears and the notebook is on pile \(x\), you must first move the notebook (this counts as one move) to any pile \(q\) where \(q \neq x\) and then stack the clothing on pile \(x\). The notebook remains on pile \(q\) until it is moved again.

Input and output formats are described below.

inputFormat

The first line contains two integers \(n\) and \(k\) \( (1 \leq n, k \leq \text{upper limit})\).

The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (each \(a_i\) is between \(1\) and \(k\)), indicating the type of each clothing item in order.

outputFormat

Output a single integer: the minimum number of moves required to relocate the notebook so that all clothing items can be stacked following the rules.

sample

3 3
1 2 3
1

</p>