inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
int n, m; int aa[MAXN]; int sum[MAXN][MAXM], sumbit[(1 << _M)]; int dp[(1 << _M)];
intmain(){ n = read(); m = read(); for (int i = 1; i <= n; ++i) { aa[i] = read(); for (int j = 1; j <= m; ++j) { sum[i][j] += sum[i - 1][j]; } sum[i][aa[i]] += 1; }
memset(dp, 0x3f, sizeof dp); dp[0] = 0; for (int stat = 1; stat <= (1 << m) - 1; ++stat) { int sumofchosen = 0; for (int i = 1; i <= m; ++i) if (stat & (1 << (i - 1))) sumofchosen += count(i); for (int i = 1; i <= m; ++i) { if (stat & (1 << (i - 1))) { int r = sumofchosen, l = (sumofchosen - count(i) + 1); dp[stat] = std::min(dp[stat], dp[stat ^ (1 << (i - 1))] + count(i) - (sum[r][i] - sum[l - 1][i])); } } } printf("%d\n", dp[(1 << m) - 1]); return0; }