#include <bits/stdc++.h>
using namespace std;
const int MAX = 40000;
int n, k, pot;
int a[MAX];
const int ALPHA = 400400;
int first[ALPHA], v[ALPHA], r[MAX];
void init() {
  for (int i = 0; i < 2 * pot; i++) first[i] = v[i] = 0;
}
void sub_update(int node, bool leaf) {
  if (v[node] != 0) {
    first[node] += v[node];
    if (!leaf) {
      v[2 * node] += v[node];
      v[2 * node + 1] += v[node];
    }
    v[node] = 0;
  }
}
void update(int node, int l, int r, int L, int R, int val) {
  sub_update(node, l == r);
  if (r < L || R < l)
    return;
  else if (L <= l && r <= R) {
    v[node] += val;
    sub_update(node, l == r);
  } else {
    update(2 * node, l, (l + r) / 2, L, R, val);
    update(2 * node + 1, (l + r) / 2 + 1, r, L, R, val);
    first[node] = max(first[2 * node], first[2 * node + 1]);
  }
}
int query(int node, int l, int r, int L, int R) {
  sub_update(node, l == r);
  if (r < L || R < l)
    return 0;
  else if (L <= l && r <= R)
    return first[node];
  else
    return max(query(2 * node, l, (l + r) / 2, L, R),
               query(2 * node + 1, (l + r) / 2 + 1, r, L, R));
}
int q(int l, int r) { return query(1, 0, pot - 1, l, r); }
int dp[52][MAX];
int aux[MAX];
void solve() {
  for (int i = 0; i < int(n); i++) aux[i + 1] = -1;
  for (int i = n - 1; i >= 0; i--) {
    r[i] = (aux[a[i]] == -1 ? n : aux[a[i]]);
    aux[a[i]] = i;
  }
  for (int i = 1; i <= k; i++) {
    init();
    for (int j = n - 1; j >= 0; j--) {
      update(1, 0, pot - 1, j + 1, r[j], 1);
      dp[i][j] = q(j + 1, n);
      update(1, 0, pot - 1, j, j, dp[i - 1][j]);
    }
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < int(n); i++) scanf("%d", a + i);
  pot = 1;
  while (pot < n + 1) pot *= 2;
  solve();
  printf("%d\n", dp[k][0]);
}
