#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4;
struct node {
  int Max, L, R, lazy;
  struct node *lchild, *rchild;
};
int n, m;
int a[maxn], dp[55][maxn] = {0}, number = 0, flag = 1;
bool vis[maxn] = {0};
void build(int k, int L, int R, node *&tree) {
  tree->L = L;
  tree->R = R;
  tree->lazy = 0;
  if (L == R) {
    tree->lchild = tree->rchild = NULL;
    tree->Max = dp[k][L];
    return;
  }
  int mid = (L + R) >> 1;
  if (flag) {
    tree->lchild = (node *)malloc(sizeof(node));
    tree->rchild = (node *)malloc(sizeof(node));
  }
  build(k, L, mid, tree->lchild);
  build(k, mid + 1, R, tree->rchild);
  tree->Max = max(tree->lchild->Max, tree->rchild->Max);
  return;
}
void push_down(node *&tree) {
  if (tree->lchild != NULL) {
    tree->lchild->lazy += tree->lazy;
    tree->lchild->Max += tree->lazy;
  }
  if (tree->rchild != NULL) {
    tree->rchild->lazy += tree->lazy;
    tree->rchild->Max += tree->lazy;
  }
  tree->lazy = 0;
}
void add(int L, int R, node *&tree) {
  if (tree->L == L && tree->R == R) {
    tree->lazy++;
    tree->Max++;
    return;
  }
  int mid = (tree->L + tree->R) >> 1;
  if (tree->lazy) push_down(tree);
  if (R <= mid)
    add(L, R, tree->lchild);
  else if (L > mid)
    add(L, R, tree->rchild);
  else {
    add(L, mid, tree->lchild);
    add(mid + 1, R, tree->rchild);
  }
  tree->Max = max(tree->lchild->Max, tree->rchild->Max);
}
int query(int L, int R, node *&tree) {
  if (tree->lazy) push_down(tree);
  if (tree->L == L && tree->R == R) return tree->Max;
  if (tree->lazy) push_down(tree);
  int mid = (tree->L + tree->R) >> 1;
  if (R <= mid)
    return query(L, R, tree->lchild);
  else if (L > mid)
    return query(L, R, tree->rchild);
  else {
    int Max1 = query(L, mid, tree->lchild),
        Max2 = query(mid + 1, R, tree->rchild);
    return max(Max1, Max2);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (!vis[a[i]]) {
      vis[a[i]] = 1;
      number++;
    }
    dp[1][i] = number;
  }
  memset(vis, 0, sizeof(vis));
  int pre[maxn] = {0}, pos[maxn] = {0};
  for (int i = 1; i <= n; i++) {
    pre[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  node *root = (node *)malloc(sizeof(node));
  for (int k = 2; k <= m; k++) {
    build(k - 1, 0, n, root);
    flag = 0;
    for (int i = 1; i <= n; i++) {
      add(pre[i], i - 1, root);
      dp[k][i] = query(0, i - 1, root);
    }
  }
  printf("%d\n", dp[m][n]);
  return 0;
}
