#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int SZ1 = 35001, SZ2 = 51;
int a[SZ1], cn[SZ1], dp[SZ2][SZ1];
int cl, cr, f;
void clr() {
  fill(cn, cn + SZ1, 0);
  f = cl = 0;
  cr = -1;
}
void add(int i) { f += (int)(cn[a[i]]++ == 0); }
void del(int i) { f -= (int)(--cn[a[i]] == 0); }
void upd_to(int l, int r) {
  while (cr < r) add(++cr);
  while (cl > l) add(--cl);
  while (cr > r) del(cr--);
  while (cl < l) del(cl++);
}
void calc(int k, int from, int to, int l, int r) {
  if (l > r) return;
  int m = (l + r) / 2;
  dp[k][m] = 0;
  int best = -1;
  for (int i = min(to, m); i >= from; i--) {
    upd_to(i, m);
    int res = dp[k - 1][i - 1] + f;
    if (res > dp[k][m]) {
      dp[k][m] = res;
      best = i;
    }
  }
  calc(k, from, best, l, m - 1);
  calc(k, best, to, m + 1, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  dp[1][0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) dp[1][i] = dp[1][i - 1];
    dp[1][i] += (int)(cn[a[i]]++ == 0);
  }
  for (int i = 2; i <= k; i++) {
    clr();
    calc(i, 1, n - 1, 1, n - 1);
  }
  cout << dp[k][n - 1] << endl;
  return 0;
}
