#include <bits/stdc++.h>
using namespace std;
unsigned short A[35005], arr[35005], mp[35005], dp[55][35005], n;
unordered_map<unsigned short, unsigned short> cache[35005];
struct node {
  node *left, *right;
  unsigned short cnt;
  node(node *l, node *r, unsigned short c) { left = l, right = r, cnt = c; }
};
node *root = new node(NULL, NULL, 0), *tree[35005];
node *add(unsigned short a, unsigned short b, unsigned short i, node *x) {
  if (a <= i && i <= b) {
    if (x == NULL) x = new node(NULL, NULL, 0);
    if (a == b) return new node(x->left, x->right, x->cnt + 1);
    node *l = add(a, ((int)a + b) / 2, i, x->left);
    node *r = add(((int)a + b) / 2 + 1, b, i, x->right);
    return new node(l, r, x->cnt + 1);
  }
  return x;
}
unsigned short query(node *x, unsigned short k, unsigned short a,
                     unsigned short b) {
  if (b <= k) return 0;
  if (a > k) return x->cnt;
  unsigned short res = 0;
  if (x->left) res += query(x->left, k, a, ((int)a + b) / 2);
  if (x->right) res += query(x->right, k, ((int)a + b) / 2 + 1, b);
  return res;
}
unsigned short getDistinct(unsigned short l, unsigned short r) {
  auto it = cache[l].find(r);
  if (it == cache[l].end())
    return cache[l][r] = query(tree[r], r, 1, 35005 + 1) -
                         query(tree[l - 1], r, 1, 35005 + 1);
  return it->second;
}
void divconq(unsigned short i, unsigned short jl, unsigned short jr,
             unsigned short kl, unsigned short kr) {
  if (jl > jr) return;
  unsigned short jmid = (jl + jr) / 2, k, mink = 0, c;
  c = getDistinct(kl, jmid);
  for (k = kl; k <= min(kr, (unsigned short)(jmid - 1)); k++) {
    if (A[k] > jmid) c--;
    if (dp[i - 1][k] + c > dp[i][jmid]) {
      dp[i][jmid] = dp[i - 1][k] + c;
      mink = k;
    }
  }
  divconq(i, jl, jmid - 1, kl, mink);
  divconq(i, jmid + 1, jr, mink, kr);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  unsigned short k, i;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
    mp[i] = 35005 + 1;
  }
  for (i = n; i >= 1; i--) {
    A[i] = mp[arr[i]];
    mp[arr[i]] = i;
  }
  tree[0] = root;
  for (i = 1; i <= n; i++) tree[i] = add(1, 35005 + 1, A[i], tree[i - 1]);
  set<unsigned short> s;
  for (i = 1; i <= n; i++) {
    s.insert(arr[i]);
    dp[1][i] = (int)s.size();
  }
  for (i = 2; i <= k; i++) divconq(i, i, n, i - 1, n - 1);
  cout << dp[k][n];
  return 0;
}
