#include <bits/stdc++.h>
using namespace std;
int n, k, a[35005];
int last[35005];
int dp[35005][55];
int tree[35005 << 2], lazy[35005 << 2];
void build(int cur, int node = 1, int l = 0, int r = n) {
  lazy[node] = 0;
  if (l == r) {
    tree[node] = dp[l][cur - 1];
    return;
  }
  build(cur, (node << 1), l, ((l + r) >> 1));
  build(cur, (node << 1 | 1), ((l + r) >> 1) + 1, r);
  tree[node] = max(tree[(node << 1)], tree[(node << 1 | 1)]);
}
void pushlazy(int node, int l, int r) {
  if (!lazy[node]) return;
  tree[node] += lazy[node];
  if (l != r)
    lazy[(node << 1)] += lazy[node], lazy[(node << 1 | 1)] += lazy[node];
  lazy[node] = 0;
}
void update(int ql, int qr, int val, int node = 1, int l = 0, int r = n) {
  pushlazy(node, l, r);
  if (l > r || l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    tree[node] += val;
    if (l != r) lazy[(node << 1)] += val, lazy[(node << 1 | 1)] += val;
    return;
  }
  update(ql, qr, val, (node << 1), l, ((l + r) >> 1));
  update(ql, qr, val, (node << 1 | 1), ((l + r) >> 1) + 1, r);
  tree[node] = max(tree[(node << 1)], tree[(node << 1 | 1)]);
}
int query(int ql, int qr, int node = 1, int l = 0, int r = n) {
  pushlazy(node, l, r);
  if (l > r || l > qr || r < ql) return 0;
  if (ql <= l && r <= qr) return tree[node];
  return max(query(ql, qr, (node << 1), l, ((l + r) >> 1)),
             query(ql, qr, (node << 1 | 1), ((l + r) >> 1) + 1, r));
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int j = 1; j <= k; j++) {
    build(j);
    memset(last, 0, sizeof(last));
    for (int i = 1; i <= n; i++) {
      update(last[a[i]], i - 1, 1);
      dp[i][j] = query(0, i - 1);
      last[a[i]] = i;
    }
  }
  printf("%d\n", dp[n][k]);
}
