Consider an operation where you choose two distinct values x and y that currently appear in the array and replace every element equal to x with y. The operation costs the number of elements that were changed.
Repeat this operation until all elements are equal. Return the minimum total cost.