#include <bits/stdc++.h>
using namespace std;
int t[4 * 35005], d[4 * 35005], w[35005];
int dp[55][35005];
int n, k;
void build(int k, int u, int l, int r) {
  if (l == r - 1) return void(t[u] = dp[k][l]);
  int m = (l + r) / 2;
  build(k, 2 * u + 1, l, m);
  build(k, 2 * u + 2, m, r);
}
void push(int u, int len) {
  if (!d[u]) return;
  t[u] += d[u];
  if (len > 1) d[2 * u + 1] += d[u], d[2 * u + 2] += d[u];
  d[u] = 0;
}
void update(int u, int l, int r, int L, int R) {
  push(u, r - l);
  if (l == L && r == R) {
    d[u]++;
    push(u, r - l);
    return;
  }
  int m = (l + r) / 2;
  if (L < m)
    update(2 * u + 1, l, m, L, min(m, R));
  else
    push(2 * u + 1, m - l);
  if (R > m)
    update(2 * u + 2, m, r, max(L, m), R);
  else
    push(2 * u + 2, r - m);
  t[u] = max(t[2 * u + 1], t[2 * u + 2]);
}
int get(int u, int l, int r, int L, int R) {
  if (L >= R) return 0;
  push(u, r - l);
  if (l == L && r == R) return t[u];
  int m = (l + r) / 2, ans = 0;
  if (L < m)
    ans = max(ans, get(2 * u + 1, l, m, L, min(m, R)));
  else
    push(2 * u + 1, m - l);
  if (R > m)
    ans = max(ans, get(2 * u + 2, m, r, max(L, m), R));
  else
    push(2 * u + 2, r - m);
  return ans;
}
int p[35005];
map<int, int> last;
void solve(int k) {
  fill_n(t, 4 * 35005, 0), fill_n(d, 4 * 35005, 0);
  build(k - 1, 0, 0, n);
  for (int i = 0; i < n; i++) {
    if (p[i] < i) update(0, 0, n, p[i], i);
    dp[k][i] = max(dp[k - 1][i], get(0, 0, n, 0, i));
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &w[i]);
  for (int i = 0; i < n; i++) {
    p[i] = -1;
    if (last.count(w[i]))
      p[i] = last[w[i]];
    else
      p[i] = 0;
    last[w[i]] = i;
  }
  set<int> s;
  for (int i = 0; i < n; i++) {
    s.insert(w[i]);
    dp[1][i] = s.size();
  }
  for (int i = 2; i <= k; i++) solve(i);
  printf("%d\n", dp[k][n - 1]);
  return 0;
}
