#include <bits/stdc++.h>
using namespace std;
int a[36000], lst[36000];
int dp[36000][55];
const int mx = int(1 << 16);
int tree[2 * mx], aval[2 * mx];
void split(int r) {
  tree[r << 1] += aval[r];
  tree[r << 1 | 1] += aval[r];
  aval[r << 1] += aval[r];
  aval[r << 1 | 1] += aval[r];
  aval[r] = 0;
}
void update(int rt, int l, int r, int u, int v, int val) {
  if (u <= l && r <= v) {
    tree[rt] += val;
    aval[rt] += val;
    return;
  }
  split(rt);
  int m = (l + r) / 2;
  if (u < m) update(rt << 1, l, m, u, v, val);
  if (m < v) update(rt << 1 | 1, m, r, u, v, val);
  tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
}
int query(int rt, int l, int r, int u, int v) {
  if (u <= l && r <= v) return tree[rt];
  int ans = 0;
  int m = (l + r) / 2;
  if (u < m) ans = max(ans, query(rt << 1, l, m, u, v));
  if (m < v) ans = max(ans, query(rt << 1 | 1, m, r, u, v));
  return ans;
}
int main() {
  int n, k;
  scanf("%d%d", &(n), &(k));
  for (int i = 1; i <= n; i++) scanf("%d", &(a[i]));
  for (int i = 1; i <= k; i++) {
    memset(lst, 0, sizeof(lst));
    memset(tree, 0, sizeof(tree));
    memset(aval, 0, sizeof(aval));
    for (int j = i; j <= n; j++) {
      int l = max(i, lst[a[j]] + 1);
      update(1, mx, mx * 2, mx + l, mx + j + 1, 1);
      update(1, mx, mx * 2, mx + j, mx + j + 1, dp[j - 1][i - 1]);
      dp[j][i] = query(1, mx, mx * 2, mx + i, mx + j + 1);
      lst[a[j]] = j;
    }
  }
  printf("%d\n", dp[n][k]);
  return 0;
}
