#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static const int BS = 1 << 22;
  static unsigned char buf[BS], *st, *ed;
  if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
  return st == ed ? EOF : *st++;
}
template <class T>
void in(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  if (f) x = -x;
}
int n, k;
int mx[35010 << 3], laz[35010 << 3];
int f[2][35010];
int rt = 1;
int pre[35010];
int lst[35010];
inline void up(int x) { mx[x] = max(mx[(x << 1)], mx[(x << 1 | 1)]); }
void build(int x, int l, int r, int op) {
  laz[x] = 0;
  if (l >= r) {
    mx[x] = f[op][l];
    return;
  }
  int mid = (l + r) >> 1;
  build((x << 1), l, mid, op);
  build((x << 1 | 1), mid + 1, r, op);
  up(x);
}
inline void down(int x) {
  if (laz[x]) {
    mx[x] += laz[x];
    laz[(x << 1)] += laz[x];
    laz[(x << 1 | 1)] += laz[x];
    laz[x] = 0;
  }
}
void add(int x, int l, int r, int ql, int qr, int k) {
  if (ql <= l && r <= qr) {
    laz[x] += k;
    down(x);
    return;
  }
  down(x);
  int mid = (l + r) >> 1;
  if (ql <= mid)
    add((x << 1), l, mid, ql, qr, k);
  else
    down((x << 1));
  if (qr > mid)
    add((x << 1 | 1), mid + 1, r, ql, qr, k);
  else
    down((x << 1 | 1));
  up(x);
}
int qmax(int x, int l, int r, int ql, int qr) {
  down(x);
  if (ql <= l && r <= qr) {
    return mx[x];
  }
  int mid = (l + r) >> 1;
  int t = 0;
  if (ql <= mid) t = qmax((x << 1), l, mid, ql, qr);
  if (qr > mid) t = max(t, qmax((x << 1 | 1), mid + 1, r, ql, qr));
  return t;
}
void print(int x, int l, int r) {
  down(x);
  if (l < r) {
    int mid = (l + r) >> 1;
    print((x << 1), l, mid);
    print((x << 1 | 1), mid + 1, r);
  }
  printf("P %d %d %d: %d\n", x, l, r, mx[x]);
}
signed main() {
  in(n), in(k);
  for (register int i = 1, t; i <= n; ++i) {
    in(t);
    pre[i] = lst[t];
    lst[t] = i;
  }
  for (register int j = 1; j <= k; ++j) {
    int op = j & 1;
    build(rt, 0, n, op ^ 1);
    for (register int i = j; i <= n; ++i) {
      add(rt, 0, n, pre[i], i - 1, 1);
      f[op][i] = qmax(rt, 0, n, 0, i - 1);
    }
  }
  printf("%d", f[k & 1][n]);
  return 0;
}
