#include <bits/stdc++.h>
using namespace std;
const int maxn = 35010, maxk = 53;
int vet[maxn];
int opt[maxk][maxn], dp[maxk][maxn], n, m;
int num[maxn], prox[maxn], ult[maxn];
struct Node {
  int v;
  Node *l, *r;
  Node() {
    v = 0;
    l = r = nullptr;
  }
};
Node *version[maxn];
void build(Node *node, int l, int r) {
  if (l == r) {
    node->v = vet[l];
    return;
  }
  int mid = (l + r) >> 1;
  node->l = new Node(), node->r = new Node();
  build(node->l, l, mid);
  build(node->r, mid + 1, r);
  node->v = node->l->v + node->r->v;
}
void update(Node *prev, Node *node, int l, int r, int idx, int val) {
  if (l == r) {
    node->v = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (idx <= mid) {
    node->r = prev->r;
    if (!node->l) node->l = new Node();
    update(prev->l, node->l, l, mid, idx, val);
  } else {
    node->l = prev->l;
    if (!node->r) node->r = new Node();
    update(prev->r, node->r, mid + 1, r, idx, val);
  }
  node->v = node->l->v + node->r->v;
}
int query(Node *node, int tl, int tr, int l, int r) {
  if (tl > r or tr < l) return 0;
  if (tl >= l and tr <= r) return node->v;
  int mid = (tl + tr) >> 1;
  return query(node->l, tl, mid, l, r) + query(node->r, mid + 1, tr, l, r);
}
void solve(int i, int l, int r) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  int qtd = query(version[mid], 1, n, max(i, opt[i][l - 1]), mid);
  for (int k = max(i, opt[i][l - 1]); k <= mid && k <= opt[i][r + 1]; k++) {
    if (dp[i][mid] < dp[i - 1][k - 1] + qtd)
      dp[i][mid] = dp[i - 1][k - 1] + qtd, opt[i][mid] = k;
    if (prox[k] > mid) qtd--;
  }
  solve(i, l, mid - 1);
  solve(i, mid + 1, r);
}
void sc(int &x) {
  register int c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
int main(void) {
  sc(n), sc(m);
  int qtd = 0;
  for (int i = 1; i <= n; i++) sc(num[i]);
  version[0] = new Node();
  build(version[0], 1, n);
  for (int i = 1; i <= n; i++) {
    Node *aux = new Node();
    version[i] = new Node();
    update(version[i - 1], aux, 1, n, i, 1);
    if (ult[num[i]])
      update(aux, version[i], 1, n, ult[num[i]], 0);
    else
      version[i] = aux;
    ult[num[i]] = i;
  }
  memset(ult, 0, sizeof ult);
  for (int i = n; i >= 1; i--) {
    prox[i] = (ult[num[i]] ? ult[num[i]] : n + 1);
    ult[num[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    opt[i][0] = 1, opt[i][n + 1] = n;
    solve(i, 1, n);
  }
  printf("%d\n", dp[m][n]);
}
