#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[35010], pre[35010], last[35010];
int f[55][35010];
struct node {
  int lc, rc, tag, f;
} t[35010 << 1];
int ptr = 0;
int newnode() { return ++ptr; }
int root;
void pushup(int rt) {
  t[rt].f = max(t[t[rt].lc].f, t[t[rt].rc].f);
  return;
}
void pushdown(int rt) {
  if (t[rt].tag == 0) return;
  t[t[rt].lc].tag += t[rt].tag;
  t[t[rt].rc].tag += t[rt].tag;
  t[t[rt].lc].f += t[rt].tag;
  t[t[rt].rc].f += t[rt].tag;
  t[rt].tag = 0;
  return;
}
void build(int &rt, int l, int r, int cur) {
  rt = newnode();
  t[rt].tag = 0;
  if (l == r) {
    t[rt].f = f[cur][l - 1];
    t[rt].lc = t[rt].rc = 0;
    return;
  }
  int mid = ((l + r) >> 1);
  build(t[rt].lc, l, mid, cur);
  build(t[rt].rc, mid + 1, r, cur);
  pushup(rt);
  return;
}
void init() {
  memset(t, 0, sizeof(t));
  ptr = 0;
  return;
}
void pt(int rt, int l, int r) {
  if (l == r) {
    cout << t[rt].f << " ";
    return;
  }
  pushdown(rt);
  int mid = ((l + r) >> 1);
  pt(t[rt].lc, l, mid);
  pt(t[rt].rc, mid + 1, r);
  return;
}
int query(int rt, int L, int R, int l, int r) {
  if (L <= l && r <= R) {
    return t[rt].f;
  }
  pushdown(rt);
  int mid = ((l + r) >> 1);
  int res = 0;
  if (L <= mid) res = max(res, query(t[rt].lc, L, R, l, mid));
  if (R >= mid + 1) res = max(res, query(t[rt].rc, L, R, mid + 1, r));
  return res;
}
void add(int rt, int L, int R, int l, int r) {
  if (L <= l && r <= R) {
    t[rt].f += 1;
    t[rt].tag += 1;
    return;
  }
  pushdown(rt);
  int mid = ((l + r) >> 1);
  if (L <= mid) add(t[rt].lc, L, R, l, mid);
  if (R >= mid + 1) add(t[rt].rc, L, R, mid + 1, r);
  pushup(rt);
  return;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pre[i] = last[a[i]];
    last[a[i]] = i;
  }
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= k; ++i) {
    init();
    build(root, 1, n, i - 1);
    for (int j = 1; j <= n; ++j) {
      add(root, pre[j] + 1, j, 1, n);
      f[i][j] = query(root, 1, j, 1, n);
    }
  }
  cout << f[k][n] << endl;
  return 0;
}
