#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35000 + 5;
int N, K, a[MAXN], pos[MAXN], f[MAXN][55];
struct Seg {
  struct tree {
    int mx, tag;
  } t[MAXN << 2];
  void mark(int k, int tag) {
    t[k].mx += tag;
    t[k].tag += tag;
  }
  void Pushdown(int k) {
    if (!t[k].tag) return;
    mark(k << 1, t[k].tag);
    mark(k << 1 | 1, t[k].tag);
    t[k].tag = 0;
  }
  void cg(int le, int ri, int k, int L, int R, int v) {
    if (le != ri) Pushdown(k);
    int mi = (le + ri) >> 1;
    if (L <= le && ri <= R) {
      mark(k, v);
      return;
    }
    if (L <= mi) cg(le, mi, k << 1, L, R, v);
    if (mi + 1 <= R) cg(mi + 1, ri, k << 1 | 1, L, R, v);
    t[k].mx = max(t[k << 1].mx, t[k << 1 | 1].mx);
  }
  int get(int le, int ri, int k, int L, int R) {
    if (le != ri) Pushdown(k);
    if (L <= le && ri <= R) return t[k].mx;
    int mi = (le + ri) >> 1, mx = 0;
    if (L <= mi) mx = max(mx, get(le, mi, k << 1, L, R));
    if (mi + 1 <= R) mx = max(mx, get(mi + 1, ri, k << 1 | 1, L, R));
    return mx;
  }
} S[55];
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= K; j++) S[j].cg(0, N, 1, 0, i - 1, 1);
    if (pos[a[i]])
      for (int j = 0; j <= K; j++) S[j].cg(0, N, 1, 0, pos[a[i]] - 1, -1);
    pos[a[i]] = i;
    for (int j = K; j >= 1; j--) {
      f[i][j] = S[j - 1].get(0, N, 1, 0, i - 1);
      S[j].cg(0, N, 1, i, i, f[i][j]);
    }
  }
  printf("%d\n", f[N][K]);
  return 0;
}
