#include <bits/stdc++.h>
using namespace std;
const int N = 35005;
pair<int, int> st[4 * N];
int lz[4 * N];
void prop(int p, int L, int R) {
  if (lz[p]) {
    st[p].first += lz[p];
    if (L < R) {
      lz[2 * p] += lz[p];
      lz[2 * p + 1] += lz[p];
    }
    lz[p] = 0;
  }
}
pair<int, int> comb(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return max(a, b);
  return min(a, b);
}
void upd(int p, int L, int R, int i, int j, int val) {
  prop(p, L, R);
  if (i > R or j < L) return;
  if (L >= i and R <= j) {
    lz[p] = val;
    prop(p, L, R);
    return;
  }
  int mid = (L + R) / 2;
  upd(2 * p, L, mid, i, j, val);
  upd(2 * p + 1, mid + 1, R, i, j, val);
  st[p] = comb(st[2 * p], st[2 * p + 1]);
}
void upd(int p, int L, int R, int pos, pair<int, int> val) {
  prop(p, L, R);
  if (pos > R or pos < L) return;
  if (L == R) {
    st[p] = val;
    return;
  }
  int mid = (L + R) / 2;
  upd(2 * p, L, mid, pos, val);
  upd(2 * p + 1, mid + 1, R, pos, val);
  st[p] = comb(st[2 * p], st[2 * p + 1]);
}
pair<int, int> query(int p, int L, int R, int i, int j) {
  prop(p, L, R);
  if (i > R or j < L) return {0, 0};
  if (L >= i and R <= j) return st[p];
  int mid = (L + R) / 2;
  return comb(query(2 * p, L, mid, i, j), query(2 * p + 1, mid + 1, R, i, j));
}
void clear(int p, int L, int R) {
  st[p] = {0, 0};
  lz[p] = 0;
  if (L == R) return;
  int mid = (L + R) / 2;
  clear(2 * p, L, mid);
  clear(2 * p + 1, mid + 1, R);
}
int n, k;
int a[N];
int dp[N], opt[N], last[N];
int f(int x) {
  clear(1, 0, n);
  for (int i = 1; i <= n; i++) last[i] = n;
  dp[n] = opt[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    upd(1, 0, n, i + 1, last[a[i]], 1);
    last[a[i]] = i;
    auto tmp = query(1, 0, n, i + 1, n);
    dp[i] = tmp.first - x;
    opt[i] = tmp.second + 1;
    upd(1, 0, n, i, {dp[i], opt[i]});
  }
  return opt[0];
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int lo = 0, hi = N, ans = 0;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (f(mid) <= k)
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  f(ans);
  printf("%d\n", dp[0] + k * ans);
}
