#include <bits/stdc++.h>
using namespace std;
int addv[35010 * 4], Max[35010 * 4];
int dp[35010], ql, qr;
int pre[35010], last[35010], a[35010];
void build(int l, int r, int o) {
  addv[o] = 0;
  if (l == r) {
    Max[o] = dp[l];
    return;
  }
  int mid = l + (r - l) / 2;
  build(l, mid, o * 2);
  build(mid + 1, r, o * 2 + 1);
  Max[o] = max(Max[o * 2], Max[o * 2 + 1]);
}
void pushdown(int o) {
  int lc = o * 2, rc = o * 2 + 1;
  if (addv[o]) {
    addv[lc] += addv[o];
    addv[rc] += addv[o];
    Max[lc] += addv[o];
    Max[rc] += addv[o];
    addv[o] = 0;
  }
}
void update(int l, int r, int o) {
  if (ql > qr) return;
  if (ql <= l && qr >= r) {
    addv[o]++;
    Max[o]++;
    return;
  }
  pushdown(o);
  int mid = l + (r - l) / 2;
  if (ql <= mid) update(l, mid, o * 2);
  if (qr > mid) update(mid + 1, r, o * 2 + 1);
  Max[o] = max(Max[o * 2], Max[o * 2 + 1]);
}
int query(int l, int r, int o) {
  if (ql <= l && qr >= r) {
    return Max[o];
  }
  pushdown(o);
  int mid = l + (r - l) / 2;
  int best = -0x3f3f3f3f;
  if (ql <= mid) best = max(best, query(l, mid, o * 2));
  if (qr > mid) best = max(best, query(mid + 1, r, o * 2 + 1));
  return best;
}
int main() {
  int n, k, cnt = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = last[a[i]];
    last[a[i]] = i;
    if (!pre[i]) {
      cnt++;
    }
    dp[i] = cnt;
  }
  for (int i = 2; i <= k; i++) {
    for (int j = 1; j < i - 1; j++) dp[j] = -1e9;
    build(1, n, 1);
    for (int j = i; j <= n; j++) {
      ql = max(pre[j], 1), qr = j - 1;
      update(1, n, 1);
      ql = 1, qr = j - 1;
      dp[j] = query(1, n, 1);
    }
  }
  cout << dp[n];
}
