#include <bits/stdc++.h>
const int maxn = 35000 + 7, maxk = 51, lo = 0x20000;
int n, di, c[maxn], bc[maxn], pc[maxn];
long long dp[maxk][maxn];
struct node {
  long long mx, d;
} seg[lo * 2];
void segRebuild() { memset(seg, 0, sizeof(seg)); }
int ql, qr, qd;
void segModify(int p = 1, int l = 0, int r = lo) {
  if (ql <= l && r <= qr) {
    seg[p].mx += qd;
    seg[p].d += qd;
    return;
  }
  seg[(p << 1)].mx += seg[p].d;
  seg[(p << 1)].d += seg[p].d;
  seg[((p << 1) | 1)].mx += seg[p].d;
  seg[((p << 1) | 1)].d += seg[p].d;
  seg[p].d = 0;
  int mid = (l + r) >> 1;
  if (ql < mid) segModify((p << 1), l, mid);
  if (mid < qr) segModify(((p << 1) | 1), mid, r);
  seg[p].mx = std::max(seg[(p << 1)].mx, seg[((p << 1) | 1)].mx);
}
int main() {
  scanf("%d%d", &n, &di);
  c[0] = 0x80000000;
  for (int i = 1; i <= n; ++i) scanf("%d", c + i);
  for (int i = 1; i <= n; ++i) {
    pc[i] = bc[c[i]];
    bc[c[i]] = i;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) dp[0][i] = 0x8000000000000000;
  for (int k = 1; k <= di; ++k) {
    segRebuild();
    for (int i = k; i <= n; ++i) {
      ql = i - 1;
      qr = i;
      qd = dp[k - 1][i - 1];
      segModify();
      ql = pc[i];
      qr = i;
      qd = 1;
      segModify();
      dp[k][i] = seg[1].mx;
    }
  }
  printf("%I64d\n", dp[di][n]);
  return 0;
}
