#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
vector<int> dp;
int readData() {
  int k;
  cin >> n >> k;
  arr.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  return k;
}
void initDp() {
  vector<bool> used(n + 1, false);
  dp.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + !used[arr[i]];
    used[arr[i]] = true;
  }
}
vector<int> tree;
vector<int> toAdd;
int buildTree(int i, int l, int r) {
  if (l == r) {
    return tree[i] = dp[l];
  }
  int m = (l + r) / 2;
  return tree[i] = max(buildTree(2 * i, l, m), buildTree(2 * i + 1, m + 1, r));
}
void push(int i, int l, int r) {
  tree[i] += toAdd[i];
  if (l != r) {
    toAdd[2 * i] += toAdd[i];
    toAdd[2 * i + 1] += toAdd[i];
  }
  toAdd[i] = 0;
}
void increment(int i, int l, int r, int lt, int rt) {
  push(i, l, r);
  if (l == lt && r == rt) {
    ++toAdd[i];
    push(i, l, r);
    return;
  }
  int m = (l + r) / 2;
  if (lt <= m) {
    increment(2 * i, l, m, lt, min(rt, m));
    tree[i] = max(tree[i], tree[2 * i]);
  }
  if (rt > m) {
    increment(2 * i + 1, m + 1, r, max(lt, m + 1), rt);
    tree[i] = max(tree[i], tree[2 * i + 1]);
  }
}
int solveSegment(int i, int l, int r, int lt, int rt) {
  push(i, l, r);
  if (l == lt && r == rt) {
    return tree[i];
  }
  int m = (l + r) / 2;
  int res = 0;
  if (lt <= m) {
    res = max(res, solveSegment(2 * i, l, m, lt, min(rt, m)));
  }
  if (rt > m) {
    res = max(res, solveSegment(2 * i + 1, m + 1, r, max(lt, m + 1), rt));
  }
  return res;
}
void updateDp() {
  vector<int> start(n + 1, 1);
  vector<int> dpNew(n + 1, 0);
  tree.assign(4 * n, 0);
  toAdd.assign(4 * n, 0);
  buildTree(1, 1, n);
  dpNew[1] = dp[1];
  for (int i = 2; i <= n; ++i) {
    increment(1, 1, n, start[arr[i]], i - 1);
    start[arr[i]] = i;
    dpNew[i] = solveSegment(1, 1, n, 1, i - 1);
  }
  swap(dp, dpNew);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int k = readData();
  initDp();
  while (--k) {
    updateDp();
  }
  cout << dp[n];
  return 0;
}
