#include <bits/stdc++.h>
using namespace std;
const int N = 35000 + 100, K = 55;
struct node {
  node *L, *R;
  int sum;
  node() {
    L = R = 0;
    sum = 0;
  }
};
inline node *build(int s, int e) {
  node *ret = new node;
  if (s == e) return ret;
  int m = s + ((e - s) >> 1);
  ret->L = build(s, m);
  ret->R = build(m + 1, e);
  return ret;
}
inline node *add(node *root, int s, int e, int idx, int val) {
  node *ret = new node();
  ret->sum = root->sum + val;
  if (s == e) return ret;
  int m = s + ((e - s) >> 1);
  if (idx <= m)
    ret->L = add(root->L, s, m, idx, val), ret->R = root->R;
  else
    ret->L = root->L, ret->R = add(root->R, m + 1, e, idx, val);
  return ret;
}
inline int query(node *root, int s, int e, int l, int r) {
  if (e < l || s > r) return 0;
  if (s >= l && e <= r) return root->sum;
  int m = s + ((e - s) >> 1);
  return query(root->L, s, m, l, r) + query(root->R, m + 1, e, l, r);
}
node *roots[N];
int dp[N][K];
int n, k, arr[N], nxt[N], d[N], li[N];
int ps = -1, pe = -1, pa = -1;
inline int distinct(int s, int e) {
  if (s == ps && e == pe + 1) {
    pa += query(roots[s], 0, n - 1, e, e);
    pe++;
  } else {
    ps = s, pe = e;
    pa = query(roots[s], 0, n - 1, s, e);
  }
  return pa;
}
inline void solve(int s, int e, int l, int r, int rem) {
  if (s > e) return;
  int m = s + ((e - s) >> 1), bst = l;
  dp[m][rem] = -1e9;
  for (int i = max(l, m); i <= r; i++) {
    int x = distinct(m, i) + dp[i + 1][rem - 1];
    if (x > dp[m][rem]) {
      dp[m][rem] = x;
      bst = i;
    }
  }
  solve(s, m - 1, l, bst, rem);
  solve(m + 1, e, bst, r, rem);
}
int main() {
  memset(li, -1, sizeof li);
  memset(nxt, -1, sizeof nxt);
  scanf("%d", &n), scanf("%d", &k);
  roots[0] = build(0, n - 1);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &arr[i]);
    if (!d[arr[i]]++) roots[0] = add(roots[0], 0, n - 1, i, 1);
    if (~li[arr[i]]) {
      nxt[li[arr[i]]] = i;
    }
    li[arr[i]] = i;
  }
  for (int i = 0; i < n; ++i) dp[i][0] = -1e9;
  for (int s = 1; s < n; s++) {
    if (~nxt[s - 1])
      roots[s] = add(roots[s - 1], 0, n - 1, nxt[s - 1], 1);
    else
      roots[s] = roots[s - 1];
  }
  for (int rem = 1; rem <= k; rem++) {
    solve(0, n - 1, 0, n - 1, rem);
  }
  cout << dp[0][k];
}
