#include <bits/stdc++.h>
using namespace std;
const int N = 35010;
int n, k, a[N], pre[N], pos[N], dp[60][N];
int tree[N * 4], lazy[N * 4];
void buildTree(int n, int l, int r, int now) {
  if (l == r) {
    tree[n] = dp[now][l - 1];
    return;
  }
  int lson = n << 1;
  int rson = (n << 1) + 1;
  int mid = (l + r) / 2;
  buildTree(lson, l, mid, now);
  buildTree(rson, mid + 1, r, now);
  tree[n] = max(tree[lson], tree[rson]);
}
void pushdown(int n, int l, int r) {
  int lson = n << 1;
  int rson = (n << 1) + 1;
  int mid = (l + r) / 2;
  lazy[lson] += lazy[n];
  lazy[rson] += lazy[n];
  tree[lson] += lazy[n];
  tree[rson] += lazy[n];
  lazy[n] = 0;
}
void update(int n, int l, int r, int lef, int rig, int add) {
  if (lef <= l && r <= rig) {
    tree[n] += add;
    lazy[n] += add;
    return;
  }
  pushdown(n, l, r);
  int lson = n << 1;
  int rson = (n << 1) + 1;
  int mid = (l + r) / 2;
  if (lef <= mid) update(lson, l, mid, lef, rig, add);
  if (rig >= mid + 1) update(rson, mid + 1, r, lef, rig, add);
  tree[n] = max(tree[lson], tree[rson]);
}
int query(int n, int l, int r, int lef, int rig) {
  if (lef <= l && r <= rig) return tree[n];
  pushdown(n, l, r);
  int lson = n << 1;
  int rson = (n << 1) + 1;
  int mid = (l + r) / 2;
  int mmax = -1;
  if (lef <= mid) mmax = max(mmax, query(lson, l, mid, lef, rig));
  if (rig >= mid + 1) mmax = max(mmax, query(rson, mid + 1, r, lef, rig));
  return mmax;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int u;
    cin >> u;
    pre[i] = pos[u];
    pos[u] = i;
  }
  for (int i = 1; i <= k; i++) {
    memset(tree, 0, sizeof(tree));
    memset(lazy, 0, sizeof(lazy));
    buildTree(1, 1, n, i - 1);
    for (int j = 1; j <= n; j++) {
      update(1, 1, n, pre[j] + 1, j, 1);
      dp[i][j] = query(1, 1, n, 1, j);
    }
  }
  cout << dp[k][n] << endl;
}
