//状态压缩dp
#include <stdio.h>
#include <string.h>
int dp[101][6][160];
int max(int a, int b) {
return a > b ? a : b;
}
int main() {
int m, k;
while (scanf("%d%d", &m, &k), m || k) {
memset(dp, 0, sizeof (dp));
int n = 1 << k, ans = 0, a;
for (int i = 1; i <= m; i++) {
scanf("%d", &a);
a--;
for (int j = 0; j < k; j++)
for (int s = 0; s < n; s++)
if ((s >> a)&1) {
if (a == j) dp[i][j][s] = max(dp[i][j][s], dp[i - 1][j][s] + 1);
else dp[i][j][s] = max(dp[i][j][s], dp[i - 1][j][s]);
} else {
dp[i][a][s | (1 << a)] = max(dp[i][a][s | (1 << a)], dp[i - 1][j][s] + 1);
dp[i][j][s] = max(dp[i][j][s], dp[i - 1][j][s]);
}
}
for (int i = 0; i < k; i++)
for (int j = 0; j < n; j++)
ans = max(ans, dp[m][i][j]);
printf("%d\n", m - ans);
}
return 0;
}