#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35000 + 24;
int n, k, pre[MAXN], dp[MAXN];
struct Color {
  int val, l, r;
} c[MAXN];
struct Node {
  int l, r, Lazy, maxval;
  Node(int _l = 0, int _r = 0, double _val = 0) {
    l = _l;
    r = _r;
    maxval = _val;
  }
} Seg[MAXN * 4];
void pushUp(int k) {
  Seg[k].maxval = max(Seg[(k << 1)].maxval, Seg[(k << 1 | 1)].maxval);
}
void pushDown(int k) {
  if (Seg[k].Lazy) {
    Seg[(k << 1)].Lazy += Seg[k].Lazy;
    Seg[(k << 1)].maxval += Seg[k].Lazy;
    Seg[(k << 1 | 1)].Lazy += Seg[k].Lazy;
    Seg[(k << 1 | 1)].maxval += Seg[k].Lazy;
    Seg[k].Lazy = 0;
  }
}
void Build(int st, int ed, int k) {
  Seg[k].l = st;
  Seg[k].r = ed;
  Seg[k].Lazy = 0;
  if (st == ed) {
    Seg[k].maxval = dp[st - 1];
    return;
  }
  int mid = (st + ed) >> 1;
  Build(st, mid, (k << 1));
  Build(mid + 1, ed, (k << 1 | 1));
  pushUp(k);
}
void Modify(int st, int ed, int k, int val) {
  if (Seg[k].l == st && Seg[k].r == ed) {
    Seg[k].maxval += val;
    Seg[k].Lazy += val;
    return;
  }
  pushDown(k);
  if (Seg[(k << 1)].r >= ed) {
    Modify(st, ed, (k << 1), val);
  } else if (Seg[(k << 1 | 1)].l <= st) {
    Modify(st, ed, (k << 1 | 1), val);
  } else {
    Modify(st, Seg[(k << 1)].r, (k << 1), val);
    Modify(Seg[(k << 1 | 1)].l, ed, (k << 1 | 1), val);
  }
  pushUp(k);
}
int Query(int st, int ed, int k) {
  if (Seg[k].l == st && Seg[k].r == ed) {
    return Seg[k].maxval;
  }
  pushDown(k);
  int res;
  if (Seg[(k << 1)].r >= ed) {
    res = Query(st, ed, (k << 1));
  } else if (Seg[(k << 1 | 1)].l <= st) {
    res = Query(st, ed, (k << 1 | 1));
  } else {
    res = max(Query(st, Seg[(k << 1)].r, (k << 1)),
              Query(Seg[(k << 1 | 1)].l, ed, (k << 1 | 1)));
  }
  pushUp(k);
  return res;
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    memset(pre, 0, sizeof(pre));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &c[i].val);
      c[i].r = i;
      c[i].l = pre[c[i].val] + 1;
      pre[c[i].val] = i;
    }
    for (int i = 1; i <= n; i++) {
      dp[i] = dp[i - 1] + (c[i].l == 1 ? 1 : 0);
    }
    for (int j = 2; j <= k; j++) {
      Build(1, n, 1);
      for (int i = 1; i <= n; i++) {
        Modify(c[i].l, c[i].r, 1, 1);
        dp[i] = Query(1, i, 1);
      }
    }
    printf("%d\n", dp[n]);
  }
  return 0;
}
