#include <bits/stdc++.h>
using namespace std;
const int N = 35000 + 7;
const int MOD = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || '9' < ch; ch = getchar())
    if (ch == '-') getchar();
  for (; '0' <= ch && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + ch - '0';
  return x * f;
}
int n, k;
int dp[N];
int p[N], l[N];
int mx[N << 2], lazy[N << 2];
void pushup(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }
void pushdown(int rt) {
  if (lazy[rt]) {
    lazy[rt << 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    mx[rt << 1] += lazy[rt];
    mx[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
  }
}
void build(int rt, int l, int r) {
  lazy[rt] = mx[rt] = 0;
  if (l == r) {
    mx[rt] = dp[l];
    return;
  }
  int m = r + l >> 1;
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    mx[rt] += v;
    lazy[rt] += v;
    return;
  }
  int m = r + l >> 1;
  pushdown(rt);
  if (L <= m) update(rt << 1, l, m, L, R, v);
  if (R > m) update(rt << 1 | 1, m + 1, r, L, R, v);
  pushup(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return mx[rt];
  int m = r + l >> 1, ans = 0;
  pushdown(rt);
  if (L <= m) ans = max(ans, query(rt << 1, l, m, L, R));
  if (R > m) ans = max(ans, query(rt << 1 | 1, m + 1, r, L, R));
  pushup(rt);
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    p[i] = l[x];
    l[x] = i;
  }
  dp[0] = 0;
  for (int i = 1; i <= k; i++) {
    build(1, 0, n);
    for (int j = i; j <= n; j++) {
      update(1, 0, n, max(p[j], i - 1), j - 1, 1);
      dp[j] = query(1, 0, n, i - 1, j - 1);
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
