#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(NULL));
const int inf = 1e9;
const int mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
  int val = 0, sign = 1;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') sign = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) val = val * 10 + ch - '0';
  return sign * val;
}
long long dp[55][35001];
int tmp[35001], w[35001];
long long add(int x) { return (++tmp[x] == 1); }
long long erase(int x) { return (--tmp[x] == 0); }
int n, k;
int a = 0, b = 0;
long long res = 0;
long long calc(int l, int r) {
  if (l > r) return 0;
  while (a > l) res += add(w[--a]);
  while (b <= r) res += add(w[b++]);
  while (a < l) res -= erase(w[a++]);
  while (b - 1 > r) res -= erase(w[--b]);
  return res;
}
void divide(int u, int l, int r, int L, int R) {
  if (l > r) return;
  int m = (l + r) / 2, opt = L;
  auto &layer = dp[u - 1];
  auto &curr = dp[u][m];
  long long to, take;
  curr = 0;
  for (int i = L; i <= min(m - 1, R); i++) {
    to = layer[i];
    take = calc(i + 1, m);
    if (to + take > curr) {
      curr = to + take;
      opt = i;
    }
  }
  divide(u, l, m - 1, L, opt);
  divide(u, m + 1, r, opt, R);
}
void solve() {
  clock_t zeit = clock();
  n = read(), k = read();
  for (int i = 0; i < n; i++) w[i] = read();
  long long curr = 0;
  set<int> c;
  for (int i = 0; i < n; i++) {
    c.insert(w[i]);
    dp[1][i] = c.size();
  }
  for (int e = 2; e <= k; e++) {
    divide(e, 0, n - 1, 0, n - 1);
    fprintf(stderr, "Time = %.3f\n", (double)(clock() - zeit) / CLOCKS_PER_SEC),
        fflush(stderr);
    zeit = clock();
  }
  printf("%I64d\n", dp[k][n - 1]);
}
int main() {
  int t = 1;
  if (0) freopen("test.out", "r", stdin);
  while (t--) {
    clock_t z = clock();
    solve();
    fprintf(stderr, "Elapsed Time: %.3f\n",
            (double)(clock() - z) / CLOCKS_PER_SEC),
        fflush(stderr);
  }
}
