#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
int n, k, i, j, a[N], dp[N], pre[N], pos[N];
struct tree {
  int lazy[N], ch[N][2], top = 1, mx[N], l[N], r[N];
  void build(int now, int L, int R) {
    if (L == R) {
      mx[now] = dp[L - 1];
      lazy[now] = 0, l[now] = L, r[now] = R;
      return;
    }
    int mid = (L + R) >> 1;
    l[now] = L, r[now] = R;
    if (L <= mid)
      top++, mx[top] = lazy[top] = 0, ch[now][0] = top, build(top, L, mid),
             mx[now] = max(mx[now], mx[ch[now][0]]);
    if (mid + 1 <= R)
      top++, mx[top] = lazy[top] = 0, ch[now][1] = top, build(top, mid + 1, R),
             mx[now] = max(mx[now], mx[ch[now][1]]);
  }
  void pushdown(int x) {
    if (ch[x][0]) mx[ch[x][0]] += lazy[x], lazy[ch[x][0]] += lazy[x];
    if (ch[x][1]) mx[ch[x][1]] += lazy[x], lazy[ch[x][1]] += lazy[x];
    lazy[x] = 0;
  }
  int ask(int now, int L, int R) {
    int ans = 0;
    if (lazy[now]) pushdown(now);
    if (l[now] == L && r[now] == R) return mx[now];
    int mid = (l[now] + r[now]) >> 1;
    if (L <= mid) ans = max(ans, ask(ch[now][0], L, min(mid, R)));
    if (mid + 1 <= R) ans = max(ans, ask(ch[now][1], max(mid + 1, L), R));
    return ans;
  }
  void add(int now, int L, int R, int num) {
    if (l[now] == L && r[now] == R) {
      lazy[now] += num;
      mx[now] += num;
      return;
    }
    int mid = (l[now] + r[now]) >> 1;
    pushdown(now);
    if (L <= mid) add(ch[now][0], L, min(mid, R), num);
    if (mid + 1 <= R) add(ch[now][1], max(mid + 1, L), R, num);
    mx[now] =
        max(ch[now][0] ? mx[ch[now][0]] : 0, ch[now][1] ? mx[ch[now][1]] : 0);
  }
} T;
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) pre[i] = pos[a[i]] + 1, pos[a[i]] = i;
  for (i = 1; i <= k; i++) {
    T.top = 1;
    T.lazy[1] = T.mx[1] = 0;
    T.build(1, 1, n);
    for (j = 1; j <= n; j++) {
      T.add(1, pre[j], j, 1);
      dp[j] = T.ask(1, 1, j);
    }
  }
  printf("%d", dp[n]);
  return 0;
}
