#include <bits/stdc++.h>
using namespace std;
const int maxn = 40100;
int n, k;
int d[maxn << 2], lazy[maxn << 2], a[maxn], pre[maxn], pos[maxn], dp[60][maxn];
void update(int o) { d[o] = max(d[o << 1], d[o << 1 | 1]); }
void pushdown(int o) {
  if (lazy[o]) {
    lazy[o << 1] += lazy[o];
    lazy[o << 1 | 1] += lazy[o];
    d[o << 1] += lazy[o];
    d[o << 1 | 1] += lazy[o];
    lazy[o] = 0;
  }
}
void build(int o, int l, int r, int last) {
  lazy[o] = 0;
  if (l == r) {
    d[o] = dp[last][l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid, last);
  build(o << 1 | 1, mid + 1, r, last);
  update(o);
}
void change(int o, int L, int R, int l, int r) {
  if (l <= L && r >= R) {
    d[o]++;
    lazy[o]++;
    return;
  }
  pushdown(o);
  int mid = (L + R) >> 1;
  if (l <= mid) change(o << 1, L, mid, l, r);
  if (r > mid) change(o << 1 | 1, mid + 1, R, l, r);
  update(o);
}
int query(int o, int L, int R, int l, int r) {
  if (l <= L && r >= R) return d[o];
  pushdown(o);
  int mid = (L + R) >> 1, ret = 0;
  if (l <= mid) ret = max(ret, query(o << 1, L, mid, l, r));
  if (r > mid) ret = max(ret, query(o << 1 | 1, mid + 1, R, l, r));
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]] + 1;
    pos[a[i]] = i;
  }
  for (int i = 1; i <= k; i++) {
    build(1, 1, n, i - 1);
    for (int j = 1; j <= n; j++) {
      change(1, 1, n, pre[j], j);
      dp[i][j] = query(1, 1, n, 1, j);
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
