#include <bits/stdc++.h>
using namespace std;
const int maxn = 45000;
int maxv[maxn * 4];
int add[maxn * 4];
int a[maxn], last[maxn], now[maxn];
int dp[maxn][55];
void pushUp(int rt) { maxv[rt] = max(maxv[rt * 2], maxv[rt * 2 + 1]); }
void pushDown(int rt) {
  if (add[rt]) {
    add[rt * 2] += add[rt];
    add[rt * 2 + 1] += add[rt];
    maxv[rt * 2] += add[rt];
    maxv[rt * 2 + 1] += add[rt];
    add[rt] = 0;
  }
}
void update(int x, int y, int c, int l, int r, int rt) {
  if (x <= l && y >= r) {
    maxv[rt] += c;
    add[rt] += c;
    return;
  }
  pushDown(rt);
  int m = (l + r) / 2;
  if (x <= m) update(x, y, c, l, m, rt * 2);
  if (y > m) update(x, y, c, m + 1, r, rt * 2 + 1);
  pushUp(rt);
}
int query(int x, int y, int l, int r, int rt) {
  if (x <= l && y >= r) {
    return maxv[rt];
  }
  pushDown(rt);
  int m = (l + r) / 2;
  int ret = 0;
  if (x <= m) ret = max(ret, query(x, y, l, m, rt * 2));
  if (y > m) ret = max(ret, query(x, y, m + 1, r, rt * 2 + 1));
  return ret;
}
int main() {
  int n, k, i, j;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(now, 0, sizeof(now));
  for (i = 1; i <= n; i++) {
    last[i] = now[a[i]];
    now[a[i]] = i;
  }
  memset(dp, 0, sizeof(dp));
  for (j = 1; j <= k; j++) {
    memset(maxv, 0, sizeof(maxv));
    memset(add, 0, sizeof(add));
    for (i = 1; i <= n; i++) update(i, i, dp[i][j - 1], 0, n, 1);
    for (int i = j; i <= n; i++) {
      update(max(last[i], j - 1), i - 1, 1, 0, n, 1);
      dp[i][j] = query(j - 1, i - 1, 0, n, 1);
    }
  }
  printf("%d\n", dp[n][k]);
  return 0;
}
