#include <bits/stdc++.h>
using namespace std;
const int N = 182, M = 10020;
int head[N], d[N], fp, dis[N], a[N], c[N];
int lim[M], nex[M], w[M], cnt = 1, to[M], inq[N], S, T, prex[N], pree[N];
queue<int> q;
const int inf = 1e9;
void add(int x, int y, int z, int cost) {
  nex[++cnt] = head[x];
  head[x] = cnt;
  to[cnt] = y;
  lim[cnt] = z;
  w[cnt] = cost;
}
void link(int x, int y, int z, int cost) {
  add(x, y, z, cost);
  add(y, x, 0, -cost);
}
int res = 0;
void dinic() {
  int flow = 0;
  while (1) {
    for (int i = 1; i <= fp; i++) dis[i] = inf;
    dis[S] = 0;
    q.push(S);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inq[u] = 0;
      for (int i = head[u]; i; i = nex[i]) {
        int v = to[i];
        if (lim[i] && dis[v] > dis[u] + w[i]) {
          dis[v] = dis[u] + w[i];
          prex[v] = u;
          pree[v] = i;
          if (!inq[v]) q.push(v), inq[v] = 1;
        }
      }
    }
    if (dis[T] == inf) break;
    int d = inf;
    for (int u = T; u != S; u = prex[u]) d = min(d, lim[pree[u]]);
    flow += d;
    res += d * dis[T];
    for (int u = T; u != S; u = prex[u])
      lim[pree[u]] -= d, lim[pree[u] ^ 1] += d;
  }
  cout << res << endl;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) c[i] = 1;
  T = n + 1, S = n + 2;
  for (int i = n; i >= 1; i--) {
    link(i, i + 1, k - 1, 0);
    link(i, i + n + 2, 1, 0);
    link(i + n + 2, T, 1, 0);
    for (int j = i + 1; j <= n; j++)
      if (a[i] == a[j]) {
        link(j - 1, i + n + 2, 1, -c[a[i]]);
        break;
      }
  }
  fp = 2 * n + 2;
  for (int i = 1; i <= n; i++) link(S, i, 1, c[a[i]]);
  dinic();
  return 0;
}
