#include <bits/stdc++.h>
using namespace std;
const int maxn = 35100;
struct SEG {
  int mx[maxn << 2], add[maxn << 2];
  void up(int x) { mx[x] = max(mx[x << 1], mx[x << 1 | 1]); }
  void down(int x) {
    if (add[x]) {
      mx[x << 1] += add[x];
      mx[x << 1 | 1] += add[x];
      add[x << 1] += add[x];
      add[x << 1 | 1] += add[x];
      add[x] = 0;
    }
  }
  void bulid(int x, int l, int r) {
    mx[x] = add[x] = 0;
    if (l == r) return;
    int m = (l + r) >> 1;
    bulid(x << 1, l, m), bulid(x << 1 | 1, m + 1, r);
  }
  void update(int L, int R, int x, int l, int r, int c) {
    if (L <= l && r <= R) {
      mx[x] += c;
      add[x] += c;
      return;
    }
    down(x);
    int m = (l + r) >> 1;
    if (L <= m) update(L, R, x << 1, l, m, c);
    if (m < R) update(L, R, x << 1 | 1, m + 1, r, c);
    up(x);
  }
  int query(int L, int R, int x, int l, int r) {
    if (L <= l && r <= R) return mx[x];
    down(x);
    int m = (l + r) >> 1;
    int ret = 0;
    if (L <= m) ret = query(L, R, x << 1, l, m);
    if (m < R) ret = max(ret, query(L, R, x << 1 | 1, m + 1, r));
    return ret;
  }
} seg[60];
int a[maxn], las[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 0; i <= k; i++) seg[i].bulid(1, 0, n);
  int tmp;
  for (int i = 1; i <= n; i++) {
    int la = las[a[i]];
    for (int j = 1; j <= min(i, k); j++) {
      seg[j - 1].update(la, i - 1, 1, 0, n, 1);
      tmp = seg[j - 1].query(0, i - 1, 1, 0, n);
      seg[j].update(i, i, 1, 0, n, tmp);
    }
    las[a[i]] = i;
  }
  printf("%d\n", tmp);
}
