#include <bits/stdc++.h>
using namespace std;
int a[35020], c[35020], f[70][35020];
int l, r, o;
inline void update(const int &x, const int &y) {
  while (x < l) o += !(c[a[--l]]++);
  while (l < x) o -= !(--c[a[l++]]);
  while (r < y) o += !(c[a[++r]]++);
  while (y < r) o -= !(--c[a[r--]]);
  return;
}
inline void solve(const int &level, const int &nowl, const int &nowr,
                  const int &askl, const int &askr) {
  int m, midpos;
  int i;
  int t;
  m = (nowl + nowr) >> 1;
  for (i = askl, midpos = -1; i <= askr && i < m; i++) {
    update(i + 1, m);
    t = f[level - 1][i] + o;
    if (midpos == -1 || f[level][m] < t) {
      midpos = i;
      f[level][m] = t;
    }
  }
  if (nowl < m) solve(level, nowl, m - 1, askl, midpos);
  if (m < nowr) solve(level, m + 1, nowr, midpos, askr);
  return;
}
int main(void) {
  int n, k;
  int i;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = l = 1, r = o = 0; i <= n; i++) {
    update(1, i);
    f[1][i] = o;
  }
  for (i = 2; i <= k; i++) solve(i, 1, n, 1, n);
  printf("%d\n", f[k][n]);
  return 0;
}
