#include <bits/stdc++.h>
using namespace std;
const int INFINITE = INT_MIN;
const int maxn = (int)1e5 + 10;
struct SegTreeNode {
  int val;
  int addMark;
};
SegTreeNode segTree[maxn * 4];
int dp[51][maxn];
int a[maxn], n, k;
int pos[maxn], pre[maxn];
void build(int root, int arr[], int istart, int iend) {
  segTree[root].addMark = 0;
  if (istart == iend)
    segTree[root].val = arr[istart - 1];
  else {
    int mid = (istart + iend) / 2;
    build(root * 2 + 1, arr, istart, mid);
    build(root * 2 + 2, arr, mid + 1, iend);
    segTree[root].val =
        max(segTree[root * 2 + 1].val, segTree[root * 2 + 2].val);
  }
}
void pushDown(int root) {
  if (segTree[root].addMark != 0) {
    segTree[root * 2 + 1].addMark += segTree[root].addMark;
    segTree[root * 2 + 2].addMark += segTree[root].addMark;
    segTree[root * 2 + 1].val += segTree[root].addMark;
    segTree[root * 2 + 2].val += segTree[root].addMark;
    segTree[root].addMark = 0;
  }
}
int query(int root, int nstart, int nend, int qstart, int qend) {
  if (qstart > nend || qend < nstart) return INFINITE;
  if (qstart <= nstart && qend >= nend) return segTree[root].val;
  pushDown(root);
  int mid = (nstart + nend) / 2;
  return max(query(root * 2 + 1, nstart, mid, qstart, qend),
             query(root * 2 + 2, mid + 1, nend, qstart, qend));
}
void update(int root, int nstart, int nend, int ustart, int uend, int addVal) {
  if (ustart > nend || uend < nstart) return;
  if (ustart <= nstart && uend >= nend) {
    segTree[root].addMark += addVal;
    segTree[root].val += addVal;
    return;
  }
  pushDown(root);
  int mid = (nstart + nend) / 2;
  update(root * 2 + 1, nstart, mid, ustart, uend, addVal);
  update(root * 2 + 2, mid + 1, nend, ustart, uend, addVal);
  segTree[root].val = max(segTree[root * 2 + 1].val, segTree[root * 2 + 2].val);
}
void init() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]] + 1;
    pos[a[i]] = i;
  }
}
void solve() {
  for (int i = 1; i <= k; i++) {
    build(0, dp[i - 1], 1, n);
    for (int j = 1; j <= n; j++) {
      update(0, 1, n, pre[j], j, 1);
      dp[i][j] = query(0, 1, n, 1, j);
    }
  }
  printf("%d\n", dp[k][n]);
}
int main() {
  init();
  solve();
  return 0;
}
