#include <bits/stdc++.h>
using namespace std;
const int MXN = 35005;
int a[MXN], lst[MXN], from[MXN], f[MXN];
int t[4 * MXN], p[4 * MXN];
void build(int lo, int hi, int x = 1) {
  p[x] = 0;
  if (lo + 1 == hi) {
    t[x] = f[lo];
    return;
  }
  int mid = (lo + hi) / 2;
  build(lo, mid, 2 * x);
  build(mid, hi, 2 * x + 1);
  t[x] = max(t[2 * x], t[2 * x + 1]);
}
void prop(int x) {
  p[2 * x] += p[x];
  t[2 * x] += p[x];
  p[2 * x + 1] += p[x];
  t[2 * x + 1] += p[x];
  p[x] = 0;
}
void add(int l, int r, int lo, int hi, int x = 1) {
  if (l >= hi || lo >= r) return;
  if (l <= lo && hi <= r) {
    t[x]++;
    p[x]++;
    return;
  }
  prop(x);
  int mid = (lo + hi) / 2;
  add(l, r, lo, mid, 2 * x);
  add(l, r, mid, hi, 2 * x + 1);
  t[x] = max(t[2 * x], t[2 * x + 1]);
}
int get(int l, int r, int lo, int hi, int x = 1) {
  if (l >= hi || lo >= r) return -1e9;
  if (l <= lo && hi <= r) return t[x];
  prop(x);
  int mid = (lo + hi) / 2;
  return max(get(l, r, lo, mid, 2 * x), get(l, r, mid, hi, 2 * x + 1));
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    from[i] = lst[a[i]];
    lst[a[i]] = i;
    f[i] = -1e9;
  }
  for (int i = 1; i <= k; ++i) {
    build(0, n + 1);
    for (int j = i; j <= n; ++j) {
      add(from[j], j, 0, n + 1);
      f[j] = get(0, j, 0, n + 1);
    }
  }
  printf("%d\n", f[n]);
}
