#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35005;
int a[MAXN], dp[55][MAXN], last[MAXN];
int maxx[MAXN << 2], lazy[MAXN << 2];
void pushup(int rt) { maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]); }
void pushdown(int rt, int len) {
  if (lazy[rt]) {
    lazy[rt << 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    maxx[rt << 1] += lazy[rt];
    maxx[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
  }
}
void update(int s, int e, int z, int l, int r, int rt) {
  if (s <= l && r <= e) {
    maxx[rt] += z;
    lazy[rt] += z;
    return;
  }
  pushdown(rt, r - l + 1);
  int m = (l + r) >> 1;
  if (s <= m) update(s, e, z, l, m, rt << 1);
  if (e > m) update(s, e, z, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int query(int s, int e, int l, int r, int rt) {
  if (s <= l && r <= e) return maxx[rt];
  pushdown(rt, r - l + 1);
  int m = (l + r) >> 1;
  int ret = 0;
  if (s <= m) ret = max(ret, query(s, e, l, m, rt << 1));
  if (e > m) ret = max(ret, query(s, e, m + 1, r, rt << 1 | 1));
  return ret;
}
bool vis[MAXN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int kind = 0;
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[a[i]]) ++kind;
    dp[1][i] = kind;
    vis[a[i]] = true;
  }
  for (int i = 2; i <= k; i++) {
    memset(lazy, 0, sizeof(lazy));
    memset(maxx, 0, sizeof(maxx));
    for (int j = 1; j <= n; j++) {
      update(j, j, dp[i - 1][j], 1, n, 1);
      last[a[j]] = 1;
    }
    for (int j = 1; j < i; j++) last[a[j]] = j;
    for (int j = i; j <= n; j++) {
      update(last[a[j]], j - 1, 1, 1, n, 1);
      dp[i][j] = query(i - 1, j - 1, 1, n, 1);
      last[a[j]] = j;
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
