#include <bits/stdc++.h>
using namespace std;
const int maxn = 35000 + 20;
int dp[maxn];
int A[maxn], pre[maxn], last[maxn];
int lazy[maxn << 2], Max[maxn << 2];
void build(int l, int r, int rt) {
  if (l == r) {
    Max[rt] = dp[l];
    lazy[rt] = 0;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]);
  lazy[rt] = 0;
}
void pushdown(int rt) {
  if (lazy[rt]) {
    lazy[rt << 1] += lazy[rt], lazy[rt << 1 | 1] += lazy[rt];
    Max[rt << 1] += lazy[rt], Max[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
  }
}
void update(int l, int r, int v, int L, int R, int rt) {
  if (l <= L && r >= R) {
    Max[rt] += v;
    lazy[rt] += v;
    return;
  }
  pushdown(rt);
  int mid = L + R >> 1;
  if (l <= mid) update(l, r, v, L, mid, rt << 1);
  if (r > mid) update(l, r, v, mid + 1, R, rt << 1 | 1);
  Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]);
}
int query(int l, int r, int L, int R, int rt) {
  if (l <= L && r >= R) {
    return Max[rt];
  }
  pushdown(rt);
  int mid = L + R >> 1, ans = 0;
  if (l <= mid) ans = max(ans, query(l, r, L, mid, rt << 1));
  if (r > mid) ans = max(ans, query(l, r, mid + 1, R, rt << 1 | 1));
  return ans;
}
int main(void) {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < maxn; i++) last[i] = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    pre[i - 1] = last[A[i]];
    last[A[i]] = i - 1;
  }
  for (int i = 1; i <= k; i++) {
    build(0, n, 1);
    dp[0] = 0;
    for (int j = 1; j <= n; j++) {
      update(pre[j - 1] + 1, j - 1, 1, 0, n, 1);
      dp[j] = query(0, j - 1, 0, n, 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}
