#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
const int POOL_SZ = 1 << 20;
const int N = 1 << 20;
struct Node {
  int lb, rb;
  int delta, max;
  Node *lc, *rc;
};
Node pool[POOL_SZ];
Node *rt, *palloc;
void pool_reset() {
  rt = NULL;
  palloc = pool;
}
Node *new_node(int lb, int rb) {
  Node *h = palloc++;
  h->lb = lb;
  h->rb = rb;
  h->delta = h->max = 0;
  h->lc = h->rc = NULL;
  return h;
}
Node *build_tree(int lb, int rb) {
  Node *h = new_node(lb, rb);
  if (lb < rb) {
    int mid = (lb + rb) / 2;
    h->lc = build_tree(lb, mid);
    h->rc = build_tree(mid + 1, rb);
  }
  return h;
}
void push_down(Node *h) {
  if (h->delta != 0) {
    h->max += h->delta;
    if (h->lb < h->rb) {
      h->lc->delta += h->delta;
      h->rc->delta += h->delta;
    }
    h->delta = 0;
  }
}
void push_up(Node *h) {
  push_down(h->lc);
  push_down(h->rc);
  h->max = max(h->lc->max, h->rc->max);
}
void tree_add(int lb, int rb, int delta, Node *h = rt) {
  if (lb > rb) return;
  push_down(h);
  if (lb <= h->lb && rb >= h->rb) {
    h->delta += delta;
    return;
  }
  int mid = (h->lb + h->rb) / 2;
  if (lb <= mid) tree_add(lb, rb, delta, h->lc);
  if (rb > mid) tree_add(lb, rb, delta, h->rc);
  push_up(h);
}
int tree_max(int lb, int rb, Node *h = rt) {
  if (lb > rb) return 0;
  push_down(h);
  if (lb <= h->lb && rb >= h->rb) return h->max;
  int mid = (h->lb + h->rb) / 2;
  int retl = 0, retr = 0;
  if (lb <= mid) retl = tree_max(lb, rb, h->lc);
  if (rb > mid) retr = tree_max(lb, rb, h->rc);
  return max(retl, retr);
}
int n, k, aa[maxn];
int l[maxn], pos[maxn];
int dp[60][maxn];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &aa[i]);
  for (int i = 1; i <= n; i++) {
    dp[1][i] = dp[1][i - 1] + ((!pos[aa[i]]) ? 1 : 0);
    l[i] = pos[aa[i]];
    pos[aa[i]] = i;
  }
  for (int p = 2; p <= k; p++) {
    pool_reset();
    rt = build_tree(1, n);
    for (int i = 1; i <= n; i++) tree_add(i, i, dp[p - 1][i], rt);
    for (int i = p; i <= n; i++) {
      tree_add(max(1, l[i]), i - 1, 1, rt);
      dp[p][i] = tree_max(1, i - 1, rt);
    }
  }
  printf("%d\n", dp[k][n]);
}
