#include <bits/stdc++.h>
namespace FASTIO {
const int LEN = 1 << 21;
char BUF[LEN], *Pin, *Pin_last, PUF[LEN], *Pout = PUF,
                                          *Pout_last = PUF + LEN - 1;
inline char Getchar() {
  return Pin == Pin_last && (Pin_last = (Pin = BUF) + fread(BUF, 1, LEN, stdin),
                             Pin == Pin_last)
             ? EOF
             : *Pin++;
}
inline void Putchar(const char x) {
  if (Pout == Pout_last) fwrite(PUF, 1, Pout - PUF, stdout), Pout = PUF;
  *Pout++ = x;
}
struct fastio_init {
  fastio_init() {}
  ~fastio_init() { fwrite(PUF, 1, Pout - PUF, stdout); }
} init_func;
template <typename T>
inline void wt(T x, char c = '\n') {
  if (x < 0) {
    x = -x;
    Putchar('-');
  }
  static char sta[sizeof(T) * 8];
  int top = 0;
  do {
    sta[top++] = x % 10;
    x /= 10;
  } while (x);
  while (top) Putchar(sta[--top] + '0');
  Putchar(c);
}
template <typename T>
inline T rd() {
  T sum = 0, fl = 1;
  char ch = Getchar();
  for (; ch < '0' || ch > '9'; ch = Getchar())
    if (ch == '-')
      fl = -1;
    else if (ch == EOF)
      exit(0);
  for (; '0' <= ch && ch <= '9'; ch = Getchar()) sum = sum * 10 + ch - '0';
  return sum * fl;
}
}  // namespace FASTIO
using namespace FASTIO;
struct Segment {
  int val, tag;
} st[35010 << 2];
int n, k;
int a[35010];
int pre[35010], head[35010];
int dp[35010];
inline void push_down(int p) {
  if (st[p].tag) {
    st[p << 1].val += st[p].tag;
    st[p << 1].tag += st[p].tag;
    st[p << 1 | 1].val += st[p].tag;
    st[p << 1 | 1].tag += st[p].tag;
    st[p].tag = 0;
  }
}
void build(int p, int l, int r) {
  st[p].tag = 0;
  if (l == r) {
    st[p].val = dp[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  st[p].val = std::max(st[p << 1].val, st[p << 1 | 1].val);
}
void change(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    st[p].tag++;
    st[p].val++;
    return;
  }
  push_down(p);
  int mid = (l + r) >> 1;
  if (L <= mid) change(p << 1, l, mid, L, R);
  if (mid < R) change(p << 1 | 1, mid + 1, r, L, R);
  st[p].val = std::max(st[p << 1].val, st[p << 1 | 1].val);
  return;
}
int ask(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return st[p].val;
  push_down(p);
  int mid = (l + r) >> 1, ret = 0;
  if (L <= mid) ret = std::max(ret, ask(p << 1, l, mid, L, R));
  if (mid < R) ret = std::max(ret, ask(p << 1 | 1, mid + 1, r, L, R));
  return ret;
}
int main() {
  n = rd<int>();
  k = rd<int>();
  for (int i = 1; i <= n; i++) a[i] = rd<int>();
  for (int i = 1; i <= n; i++) {
    pre[i] = head[a[i]];
    head[a[i]] = i;
  }
  for (int j = 1; j <= k; j++) {
    build(1, 0, n);
    for (int i = j; i <= n; i++) {
      change(1, 0, n, pre[i], i - 1);
      dp[i] = ask(1, 0, n, 0, i - 1);
    }
  }
  wt(dp[n]);
  return 0;
}
