#include <bits/stdc++.h>
using namespace std;
int n, k, a[35000 + 10], sum[35000 + 10 << 2], last[35000 + 10],
    now[35000 + 10], f[35000 + 10], add[35000 + 10 << 2];
void pushup(int rt) { sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]); }
void build(int l, int r, int rt) {
  add[rt] = 0;
  if (l == r) {
    sum[rt] = f[l];
    return;
  }
  int m = (r + l) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void pushdown(int rt) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    sum[rt << 1] += add[rt];
    sum[rt << 1 | 1] += add[rt];
    add[rt] = 0;
  }
}
void update(int L, int R, int C, int l, int r, int rt) {
  if (L <= l && r <= R) {
    sum[rt] += C;
    add[rt] += C;
    return;
  }
  int m = (l + r) >> 1;
  pushdown(rt);
  if (L <= m) update(L, R, C, l, m, rt << 1);
  if (R > m) update(L, R, C, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && R >= r) return sum[rt];
  int m = (r + l) >> 1;
  pushdown(rt);
  int ans = 0;
  if (L <= m) ans = max(query(L, R, l, m, rt << 1), ans);
  if (R > m) ans = max(query(L, R, m + 1, r, rt << 1 | 1), ans);
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(last, 0, sizeof(last));
  memset(now, 0, sizeof(now));
  for (int i = 1; i <= n; i++) {
    last[i] = now[a[i]];
    now[a[i]] = i;
  }
  for (int i = 1; i <= k; i++) {
    build(0, n, 1);
    for (int j = 1; j <= n; j++) {
      update(last[j], j - 1, 1, 0, n, 1);
      f[j] = query(0, j - 1, 0, n, 1);
    }
  }
  printf("%d\n", f[n]);
  return 0;
}
