#include <bits/stdc++.h>
using namespace std;
struct Node {
  int val;
  Node *left, *right;
  Node(Node *l, Node *r, int v) { left = l, right = r, val = v; }
};
int N, K;
int A[35000 + 2], M[35000 + 1];
vector<int> dp1, dp2;
vector<Node *> root;
Node *build(int L, int R) {
  if (L == R) return new Node(NULL, NULL, 0);
  int mid = (L + R) / 2;
  return new Node(build(L, mid), build(mid + 1, R), 0);
}
Node *update(Node *prev, int L, int R, int pos, int value) {
  if (L == R) return new Node(NULL, NULL, value);
  int mid = (L + R) / 2;
  Node *nl, *nr;
  if (pos <= mid) {
    nl = update(prev->left, L, mid, pos, value);
    nr = prev->right;
  } else {
    nl = prev->left;
    nr = update(prev->right, mid + 1, R, pos, value);
  }
  return new Node(nl, nr, nl->val + nr->val);
}
int query(Node *n, int curL, int curR, int L, int R) {
  if (curL > R || curR < L || curL > curR) return 0;
  if (L <= curL && curR <= R) return n->val;
  int mid = (curL + curR) / 2;
  return query(n->left, curL, mid, L, R) + query(n->right, mid + 1, curR, L, R);
}
int query(int ver, int L, int R) { return query(root[ver], 1, N, L, R); }
void newroot(int pos, int value) {
  if (pos == 0)
    root.push_back(root.back());
  else
    root.push_back(update(root.back(), 1, N, pos, value));
}
int calc(int a, int b) { return query(b, a, b); }
unordered_map<int, int> queries[35000 + 1];
unordered_map<int, int>::iterator it;
void solve(int l, int r, int optl, int optr) {
  if (l > r) return;
  int mid = (l + r) / 2, opt = optl, diff = 0, best = 0;
  auto &cache = queries[mid];
  for (int k = optl; k <= min(mid, optr); k++) {
    it = cache.find(k);
    if (it != cache.end())
      diff = it->second;
    else {
      diff = calc(k, mid);
      cache[k] = diff;
    }
    if (dp1[k - 1] + diff > best) best = dp1[k - 1] + diff, opt = k;
  }
  dp2[mid] = best;
  solve(l, mid - 1, optl, opt);
  solve(mid + 1, r, opt, optr);
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> A[i];
  root.push_back(build(1, N));
  for (int i = 1; i <= N; i++) {
    root.push_back(update(root[i - 1], 1, N, i, 1));
    if (M[A[i]] != 0) root.back() = update(root.back(), 1, N, M[A[i]], 0);
    M[A[i]] = i;
  }
  dp1.resize(N + 2, 0);
  dp2.resize(N + 2, 0);
  for (int i = 1; i <= K; i++) {
    solve(1, N, 1, N);
    dp1 = dp2;
  }
  cout << dp1[N] << "\n";
  return 0;
}
